Skip to content

Commit

Permalink
feat(Dropdown): add a11y prop to tab moves focus (#1600)
Browse files Browse the repository at this point in the history
This adds a new a11y prop to Dropdrop, defaults to true.
When the a11y prop is explicitly set to false:
This changes the way tab works within the Dropdown.
tab/shift-tab will move focus to the next logic item:
tab will move down until the end. Then, at the end of the menu it will focus the next focusable item on the page and close the menu.
shift-tab will move up until the start. Thenm, at the beginning of the menu it will focus the toggle and close the menu.

Fixes #1441
  • Loading branch information
TheSharpieOne committed Oct 3, 2019
1 parent 3bd4182 commit 1bd965f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/lib/Components/DropdownsPage.js
Expand Up @@ -57,6 +57,7 @@ export default class DropdownPage extends React.Component {
<pre>
<PrismCode className="language-jsx">
{`Dropdown.propTypes = {
a11y: PropTypes.bool, // defaults to true. Set to false to enable more bootstrap like tabbing behavior
disabled: PropTypes.bool,
direction: PropTypes.oneOf(['up', 'down', 'left', 'right']),
group: PropTypes.bool,
Expand Down
4 changes: 3 additions & 1 deletion src/Dropdown.js
Expand Up @@ -9,6 +9,7 @@ import { DropdownContext } from './DropdownContext';
import { mapToCssModules, omit, keyCodes, tagPropType } from './utils';

const propTypes = {
a11y: PropTypes.bool,
disabled: PropTypes.bool,
direction: PropTypes.oneOf(['up', 'down', 'left', 'right']),
group: PropTypes.bool,
Expand All @@ -27,6 +28,7 @@ const propTypes = {
};

const defaultProps = {
a11y: true,
isOpen: false,
direction: 'down',
nav: false,
Expand Down Expand Up @@ -114,7 +116,7 @@ class Dropdown extends React.Component {
handleKeyDown(e) {
if (
/input|textarea/i.test(e.target.tagName)
|| (keyCodes.tab === e.which && e.target.getAttribute('role') !== 'menuitem')
|| (keyCodes.tab === e.which && (e.target.getAttribute('role') !== 'menuitem' || !this.props.a11y))
) {
return;
}
Expand Down

0 comments on commit 1bd965f

Please sign in to comment.