Skip to content

Commit

Permalink
Merge pull request #11 from lifenautjoe/bugfix/enter-should-remove-focus
Browse files Browse the repository at this point in the history
Bugfix/enter should remove focus
  • Loading branch information
Joel Hernández authored Apr 8, 2018
2 parents 00b8724 + 1a5bfb5 commit c288bb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/droppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class Droppable {
private onElementKeyDown(e: { [key: string]: any }) {
if (e['keyCode'] === Droppable.ENTER_KEY_CODE) {
this.promptForFiles();
this.element.blur();
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/droppable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,22 @@ describe('Droppable', () => {

expect(mockFn).toHaveBeenCalled();
});

it('should call this.element.blur()', () => {
const element = document.createElement('div');
const droppable = new Droppable({
element
});

const mockFn = spyOn(element, 'blur');

droppable['promptForFiles'] = () => {};

const keyDownEvent = new KeyboardEvent('keydown', { keyCode: 13 });
droppable['onElementKeyDown'](keyDownEvent);

expect(mockFn).toHaveBeenCalled();
});
});

describe('when the key is not enter', () => {
Expand Down

0 comments on commit c288bb8

Please sign in to comment.