Skip to content

Commit

Permalink
fix(Select): update keyboard interaction to correspond with specifica…
Browse files Browse the repository at this point in the history
…tion (#1176)
  • Loading branch information
inigomontoya722 authored Nov 30, 2023
1 parent e1ce48f commit 504b05c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
handleOptionClick(getActiveItem(listRef));
}
}
if ([KeyCode.ARROW_DOWN, KeyCode.ARROW_UP].includes(e.key) && !open) {
e.preventDefault();
toggleOpen();
}

listRef?.current?.onKeyDown(e);
},
Expand Down
16 changes: 16 additions & 0 deletions src/components/Select/__tests__/Select.base-actions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ describe('Select base actions', () => {
await user.keyboard('[Space]');
getByTestId(SelectQa.POPUP);
});

test('ArrowUp', async () => {
const {getByTestId} = setup();
const user = userEvent.setup();
await user.keyboard('[Tab]');
await user.keyboard('[ArrowUp]');
getByTestId(SelectQa.POPUP);
});

test('ArrowDown', async () => {
const {getByTestId} = setup();
const user = userEvent.setup();
await user.keyboard('[Tab]');
await user.keyboard('[ArrowDown]');
getByTestId(SelectQa.POPUP);
});
});

describe('initial state', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const KeyCode = {
SPACEBAR: ' ',
SPACEBAR_OLD: 'Spacebar',
ESCAPE: 'Escape',
ARROW_UP: 'ArrowUp',
ARROW_DOWN: 'ArrowDown',
};

0 comments on commit 504b05c

Please sign in to comment.