Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ScrollLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ var ScrollLock = function (_Component) {
}, {
key: 'onKeyDownHandler',
value: function onKeyDownHandler(e) {
if (e.target !== this.scrollingElement) {
return;
}

if (upKeys.indexOf(e.keyCode) >= 0) {
this.handleEventDelta(e, -1);
} else if (downKeys.indexOf(e.keyCode) >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/ScrollLock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export default class ScrollLock extends Component {
}

onKeyDownHandler(e) {
if (e.target !== this.scrollingElement) {
return;
}

if (upKeys.indexOf(e.keyCode) >= 0) {
this.handleEventDelta(e, -1);
} else if (downKeys.indexOf(e.keyCode) >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions test/ScrollLock.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ describe('ScrollLock', () => {
component = scrollLockInstance();
component.handleEventDelta = jest.fn();
});
it('should not call handleEventDelta if keydown target is not the scrolling element', () => {
component.onKeyDownHandler({ keyCode: 32, target: <input /> });
expect(component.handleEventDelta).toHaveBeenCalledTimes(0);
});
it('should call handleEventDelta with delta of 1 for space bar', () => {
const synthEvent = { keyCode: 32 };
component.onKeyDownHandler(synthEvent);
Expand Down