Skip to content

fix form entry within scrolllock #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2017
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