Skip to content

Commit

Permalink
feat: added support for Alt+Down Arrow and Alt+Up Arrow in ComboB…
Browse files Browse the repository at this point in the history
…ox (#14892)

* feat: added support

* feat: added test

* fix: tests
  • Loading branch information
k-rajat19 authored Nov 27, 2023
1 parent ffaf3e8 commit 128836e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
generateGenericItem,
} from '../ListBox/test-helpers';
import ComboBox from '../ComboBox';
import { act } from 'react-dom/test-utils';

const findInputNode = () => screen.getByRole('combobox');
const openMenu = async () => {
Expand Down Expand Up @@ -249,5 +250,20 @@ describe('ComboBox', () => {
expect(firstListBox()).toBeEmptyDOMElement();
expect(secondListBox()).toBeEmptyDOMElement();
});
it('should open menu without moving focus on pressing Alt+ DownArrow', async () => {
render(<ComboBox {...mockProps} />);
act(() => {
screen.getByRole('combobox').focus();
});
await userEvent.keyboard('{Alt>}{ArrowDown}');
assertMenuOpen(mockProps);
});

it('should close menu and return focus to combobox on pressing Alt+ UpArrow', async () => {
render(<ComboBox {...mockProps} />);
await openMenu();
await userEvent.keyboard('{Alt>}{ArrowUp}');
assertMenuClosed(mockProps);
});
});
});
13 changes: 13 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,19 @@ const ComboBox = forwardRef(
event.target.value.length
);
}

if (event.altKey && event.key == 'ArrowDown') {
event.preventDownshiftDefault = true;
if (!isOpen) {
toggleMenu();
}
}
if (event.altKey && event.key == 'ArrowUp') {
event.preventDownshiftDefault = true;
if (isOpen) {
toggleMenu();
}
}
},
});

Expand Down

0 comments on commit 128836e

Please sign in to comment.