Skip to content

Commit 0b4309b

Browse files
tech4him1okonet
authored andcommitted
feat: Add enable prop to control sync behavior (#18)
1 parent 5494e52 commit 0b4309b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ScrollSync.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export default class ScrollSync extends Component {
1212
children: PropTypes.element.isRequired,
1313
proportional: PropTypes.bool,
1414
vertical: PropTypes.bool,
15-
horizontal: PropTypes.bool
15+
horizontal: PropTypes.bool,
16+
enabled: PropTypes.bool
1617
};
1718

1819
static defaultProps = {
1920
proportional: true,
2021
vertical: true,
21-
horizontal: true
22+
horizontal: true,
23+
enabled: true
2224
};
2325

2426
static childContextTypes = {
@@ -75,6 +77,10 @@ export default class ScrollSync extends Component {
7577
}
7678

7779
handlePaneScroll = (node, group) => {
80+
if (!this.props.enabled) {
81+
return
82+
}
83+
7884
window.requestAnimationFrame(() => {
7985
this.syncScrollPositions(node, group)
8086
})

src/example.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
To use ScrollSync you have to wrap your scrollable content (ensure that you have `overflow: auto`
22
in CSS) in `ScrollSyncPane` and then wrap everything in `ScrollSync`.
3+
4+
If you want to provide a toggle for users to turn the scroll syncing on and off, you can use the `enabled={false}` setting on the main `ScrollSync` element. Note that this disables the scroll syncing for all groups.
35

46
```
57
<ScrollSync>
@@ -102,3 +104,4 @@ Provide an arbitrary group name in the `group` prop to ScrollSyncPane components
102104
</div>
103105
</ScrollSync>
104106
```
107+

0 commit comments

Comments
 (0)