Skip to content

Commit

Permalink
Fix keyboard navigation when using menu dropdown with multiple option (
Browse files Browse the repository at this point in the history
  • Loading branch information
jroofsf authored Jul 3, 2023
1 parent d55aeeb commit 549b006
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions components/menu-dropdown/__tests__/dropdown.browser-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ describe('SLDSMenuDropdown', function () {
);
expect(firstNode).attr('role', 'menuitemcheckbox');
});

it('moves focus to next item after keyboard selection', function () {
const nodes = getNodes({ wrapper: this.wrapper });
nodes.trigger.simulate('click', {});
const openNodes = getNodes({ wrapper: this.wrapper });
openNodes.menu.simulate('keyDown', keyObjects.DOWN);
openNodes.menu.simulate('keyDown', keyObjects.ENTER);
openNodes.menu.simulate('keyDown', keyObjects.DOWN);
openNodes.menu.simulate('keyDown', keyObjects.ENTER);

const secondNode = openNodes.menu.find('.slds-dropdown__item a').at(1);
expect(secondNode.getDOMNode().getAttribute('aria-checked')).to.not.equal(
'true'
);
});
});

// Hover and hybrid hover UX patterns are not approved UX patterns due to accessibility concerns
Expand Down
5 changes: 4 additions & 1 deletion components/menu-dropdown/menu-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,10 @@ class MenuDropdown extends React.Component {

// This is a bit of an anti-pattern, but it has the upside of being a nice default. Component authors can always override to only set state and do their own focusing in their subcomponents.
handleKeyboardFocus = (focusedIndex) => {
if (this.state.focusedIndex !== focusedIndex) {
if (
this.state.focusedIndex !== focusedIndex &&
focusedIndex !== undefined
) {
this.setState({ focusedIndex });
}

Expand Down

0 comments on commit 549b006

Please sign in to comment.