Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
feat(multi-select): address accessibility tabbing issue (#1731)
Browse files Browse the repository at this point in the history
* Added keydown to open, fixed a11y tabbing issue

* Linting

* Addressed reviews

* fixup

* linting

* added test coverage for list-box

* ran prettier
  • Loading branch information
yacineMTB authored and joshblack committed Mar 8, 2019
1 parent b3462ea commit f288b7c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ exports[`DropdownV2 should render 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField
aria-expanded={false}
Expand Down Expand Up @@ -246,7 +246,7 @@ exports[`DropdownV2 should render DropdownItem components 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField
aria-expanded={true}
Expand Down Expand Up @@ -660,7 +660,7 @@ exports[`DropdownV2 should render custom item components 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField
aria-expanded={true}
Expand Down Expand Up @@ -966,7 +966,7 @@ exports[`DropdownV2 should render with strings as items 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField
aria-expanded={true}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ListBox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ListBox = ({
invalid,
invalidText,
light,
innerTabIndex,
...rest
}) => {
const className = cx({
Expand All @@ -56,7 +57,7 @@ const ListBox = ({
{...rest}
role="listbox"
aria-label={ariaLabel}
tabIndex="0"
tabIndex={innerTabIndex || 0}
className={className}
ref={innerRef}
onKeyDown={handleOnKeyDown}
Expand Down
10 changes: 10 additions & 0 deletions src/components/ListBox/__tests__/ListBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ describe('ListBox', () => {
.includes(mockProps.className)
).toBe(true);
});

it('should pass down innerTabIndex prop to the inner divs tabIndex', () => {
mockProps.innerTabIndex = -1;
const wrapper = mount(<ListBox {...mockProps} />);
expect(wrapper.children().prop('tabIndex')).toBe(-1);
});
it('should default the inner divs tabIndex to 0 if no innerTabIndex prop', () => {
const wrapper = mount(<ListBox {...mockProps} />);
expect(wrapper.children().prop('tabIndex')).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`ListBox should render 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField>
<div
Expand Down
8 changes: 7 additions & 1 deletion src/components/MultiSelect/FilterableMultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,16 @@ export default class FilterableMultiSelect extends React.Component {
handleOnStateChange = changes => {
const { type } = changes;
switch (type) {
case Downshift.stateChangeTypes.keyDownArrowDown:
case Downshift.stateChangeTypes.keyDownArrowUp:
case Downshift.stateChangeTypes.itemMouseEnter:
this.setState({ highlightedIndex: changes.highlightedIndex });
break;
case Downshift.stateChangeTypes.keyDownArrowDown:
this.setState({
highlightedIndex: changes.highlightedIndex,
isOpen: true,
});
break;
case Downshift.stateChangeTypes.keyDownEscape:
case Downshift.stateChangeTypes.mouseUp:
this.setState({ isOpen: false });
Expand Down Expand Up @@ -254,6 +259,7 @@ export default class FilterableMultiSelect extends React.Component {
disabled={disabled}
invalid={invalid}
invalidText={invalidText}
innerTabIndex="-1"
{...getRootProps({ refKey: 'innerRef' })}>
<ListBox.Field {...getButtonProps({ disabled })}>
{selectedItem.length > 0 && (
Expand Down
1 change: 1 addition & 0 deletions src/components/MultiSelect/MultiSelect-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ storiesOf('MultiSelect', module)
} = props();
const ComponentToUse = !filterable ? MultiSelect : MultiSelect.Filterable;
const placeholder = !filterable ? undefined : defaultPlaceholder;

return (
<div style={{ width: 300 }}>
<ComponentToUse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ exports[`MultiSelect.Filterable should render 1`] = `
className="bx--multi-select bx--combo-box"
disabled={false}
innerRef={[Function]}
innerTabIndex="-1"
type="default"
>
<div
Expand All @@ -84,7 +85,7 @@ exports[`MultiSelect.Filterable should render 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex="-1"
>
<ListBoxField
aria-expanded={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`MultiSelect should render 1`] = `
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
tabIndex="0"
tabIndex={0}
>
<ListBoxField
aria-expanded={false}
Expand Down

0 comments on commit f288b7c

Please sign in to comment.