Skip to content
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

[a11y] Closes calendar when escape is pressed #1595

Closed
wants to merge 7 commits into from

Conversation

iambrandonn
Copy link

Fixes #18

@coveralls
Copy link

coveralls commented Mar 25, 2019

Coverage Status

Coverage decreased (-0.7%) to 83.843% when pulling a9a895a on iambrandonn:close-on-escape into 78c20b6 on airbnb:master.

showKeyboardShortcuts: false,
});

onFocusChange(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this maybe be in a callback to setState, so it's sure to happen after the state is set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I can do that.

@iambrandonn iambrandonn changed the title Closes calendar when escape is pressed [a11y] Closes calendar when escape is pressed Apr 8, 2019
@iambrandonn
Copy link
Author

@ljharb Any other thoughts on this PR?

@ljharb
Copy link
Member

ljharb commented Apr 8, 2019

Seems good to me; I'm going to defer to @backwardok and @majapw here.

@ljharb ljharb requested review from majapw and backwardok April 8, 2019 19:45
src/components/DateRangePicker.jsx Show resolved Hide resolved
@@ -159,6 +162,8 @@ class DateInput extends React.PureComponent {
} else if (key === '?') {
e.preventDefault();
onKeyDownQuestionMark(e);
} else if (key === 'Escape') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you'd also want to add escape key handling within the calendar overlay itself as well.

@iambrandonn
Copy link
Author

@backwardok I've made a few more changes so the calendar will close consistently, whether the user gained focus by pressing the down arrow key or by pushing the tab key. It seems to be working well for me. I'm willing to set up a github pages branch so you can see it working... but for some reason build-storybook is giving errors like this (even on the master branch without my changes):

Property declarations[0] of VariableDeclaration expected node to be of a type ["VariableDeclarator"]

@@ -267,6 +269,15 @@ class DateRangePicker extends React.PureComponent {
});
}

onKeyDownTab(evt) {
const { focusedInput } = this.props;
if (focusedInput !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another change (#1553) that's going to make it so that there's only one instance of the calendar, and it sits between the two inputs. This will end up breaking the behavior you're adding here, since it will cause a keyboard trap on the last input.

In general, it's not advised to manually handle focus from tabbing. What's the need for adding this behavior here?

This was referenced Jun 4, 2019
@iambrandonn iambrandonn closed this Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateRangePicker/SingleDatePicker should close on Escape Keypress
4 participants