Skip to content

Commit

Permalink
Merge pull request react-dates#1464 from cshaver/crit--keyboard-close…
Browse files Browse the repository at this point in the history
…-shortcuts-panel

[a11y] Remove space/enter onKeyDown handling for open/close keyboard shortcuts panel
  • Loading branch information
majapw authored Nov 14, 2018
2 parents e76e308 + ca4b67c commit 9426234
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
10 changes: 0 additions & 10 deletions src/components/DayPickerKeyboardShortcuts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class DayPickerKeyboardShortcuts extends React.PureComponent {
// amounts to a very basic focus trap. The user can exit the panel by "pressing" the
// close button or hitting escape
switch (e.key) {
case 'Enter':
case ' ':
case 'Spacebar': // for older browsers
case 'Escape':
closeKeyboardShortcutsPanel();
break;
Expand Down Expand Up @@ -190,13 +187,6 @@ class DayPickerKeyboardShortcuts extends React.PureComponent {
type="button"
aria-label={toggleButtonText}
onClick={this.onShowKeyboardShortcutsButtonClick}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
} else if (e.key === 'Space') {
this.onShowKeyboardShortcutsButtonClick(e);
}
}}
onMouseUp={(e) => {
e.currentTarget.blur();
}}
Expand Down
19 changes: 4 additions & 15 deletions test/components/DayPickerKeyboardShortcuts_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ describe('DayPickerKeyboardShortcuts', () => {
buttonWrapper.simulate('click');
expect(openKeyboardShortcutsPanelStub.callCount).to.equal(1);
});

it('onKeyDown Space calls onShowKeyboardShortcutsButtonClick', () => {
buttonWrapper.prop('onKeyDown')({ ...event, key: 'Space' });
expect(openKeyboardShortcutsPanelStub.callCount).to.equal(1);
});

it('onKeyDown Enter calls e.preventDefault and NOT onShowKeyboardShortcutsButtonClick', () => {
buttonWrapper.prop('onKeyDown')({ ...event, key: 'Enter' });
expect(event.preventDefault.callCount).to.equal(1);
expect(openKeyboardShortcutsPanelStub.notCalled).to.equal(true);
});
});

describe('when Mouse Up', () => {
Expand Down Expand Up @@ -215,10 +204,10 @@ describe('DayPickerKeyboardShortcuts', () => {
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(1);
});

it('onKeyDown Space calls e.stopPropagation and onShowKeyboardShortcutsButtonClick', () => {
it('onKeyDown calls e.stopPropagation and NOT onShowKeyboardShortcutsButtonClick', () => {
closeButton.prop('onKeyDown')({ ...event, key: ' ' });
expect(event.stopPropagation.callCount).to.equal(1);
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(1);
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(0);
});

it('onKeyDown Escape calls e.stopPropagation and onShowKeyboardShortcutsButtonClick', () => {
Expand All @@ -227,10 +216,10 @@ describe('DayPickerKeyboardShortcuts', () => {
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(1);
});

it('onKeyDown Enter calls e.stopPropagation and onShowKeyboardShortcutsButtonClick', () => {
it('onKeyDown calls e.stopPropagation and NOT onShowKeyboardShortcutsButtonClick', () => {
closeButton.prop('onKeyDown')({ ...event, key: 'Enter' });
expect(event.stopPropagation.callCount).to.equal(1);
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(1);
expect(closeKeyboardShortcutsPanelStub.callCount).to.equal(0);
});

it('onKeyDown Tab calls e.stopPropagation and e.preventDefault and NOT onShowKeyboardShortcutsButtonClick', () => {
Expand Down

0 comments on commit 9426234

Please sign in to comment.