Skip to content

Commit 196e3ef

Browse files
authored
fix form entry within scrolllock (#15)
1 parent fbd3c1f commit 196e3ef

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/ScrollLock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ var ScrollLock = function (_Component) {
111111
}, {
112112
key: 'onKeyDownHandler',
113113
value: function onKeyDownHandler(e) {
114+
if (e.target !== this.scrollingElement) {
115+
return;
116+
}
117+
114118
if (upKeys.indexOf(e.keyCode) >= 0) {
115119
this.handleEventDelta(e, -1);
116120
} else if (downKeys.indexOf(e.keyCode) >= 0) {

src/ScrollLock.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export default class ScrollLock extends Component {
9595
}
9696

9797
onKeyDownHandler(e) {
98+
if (e.target !== this.scrollingElement) {
99+
return;
100+
}
101+
98102
if (upKeys.indexOf(e.keyCode) >= 0) {
99103
this.handleEventDelta(e, -1);
100104
} else if (downKeys.indexOf(e.keyCode) >= 0) {

test/ScrollLock.test.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ describe('ScrollLock', () => {
128128
component = scrollLockInstance();
129129
component.handleEventDelta = jest.fn();
130130
});
131+
it('should not call handleEventDelta if keydown target is not the scrolling element', () => {
132+
component.onKeyDownHandler({ keyCode: 32, target: <input /> });
133+
expect(component.handleEventDelta).toHaveBeenCalledTimes(0);
134+
});
131135
it('should call handleEventDelta with delta of 1 for space bar', () => {
132136
const synthEvent = { keyCode: 32 };
133137
component.onKeyDownHandler(synthEvent);

0 commit comments

Comments
 (0)