Skip to content

Commit 549b006

Browse files
authored
Fix keyboard navigation when using menu dropdown with multiple option (#3122)
1 parent d55aeeb commit 549b006

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

components/menu-dropdown/__tests__/dropdown.browser-test.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,21 @@ describe('SLDSMenuDropdown', function () {
394394
);
395395
expect(firstNode).attr('role', 'menuitemcheckbox');
396396
});
397+
398+
it('moves focus to next item after keyboard selection', function () {
399+
const nodes = getNodes({ wrapper: this.wrapper });
400+
nodes.trigger.simulate('click', {});
401+
const openNodes = getNodes({ wrapper: this.wrapper });
402+
openNodes.menu.simulate('keyDown', keyObjects.DOWN);
403+
openNodes.menu.simulate('keyDown', keyObjects.ENTER);
404+
openNodes.menu.simulate('keyDown', keyObjects.DOWN);
405+
openNodes.menu.simulate('keyDown', keyObjects.ENTER);
406+
407+
const secondNode = openNodes.menu.find('.slds-dropdown__item a').at(1);
408+
expect(secondNode.getDOMNode().getAttribute('aria-checked')).to.not.equal(
409+
'true'
410+
);
411+
});
397412
});
398413

399414
// Hover and hybrid hover UX patterns are not approved UX patterns due to accessibility concerns

components/menu-dropdown/menu-dropdown.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,10 @@ class MenuDropdown extends React.Component {
806806

807807
// 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.
808808
handleKeyboardFocus = (focusedIndex) => {
809-
if (this.state.focusedIndex !== focusedIndex) {
809+
if (
810+
this.state.focusedIndex !== focusedIndex &&
811+
focusedIndex !== undefined
812+
) {
810813
this.setState({ focusedIndex });
811814
}
812815

0 commit comments

Comments
 (0)