Skip to content

Commit

Permalink
[core] Remove usage of deprecated .keyCode
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 11, 2020
1 parent ad558cb commit 58a899e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
6 changes: 1 addition & 5 deletions docs/src/modules/components/AppSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ export default function AppSearch() {

React.useEffect(() => {
const handleKeyDown = (nativeEvent) => {
// Use nativeEvent.keyCode to support IE 11
if (
[
191, // '/'
83, // 's'
].indexOf(nativeEvent.keyCode) !== -1 &&
['/', 's'].indexOf(nativeEvent.key) !== -1 &&
document.activeElement.nodeName === 'BODY' &&
document.activeElement !== inputRef.current
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ function Unstable_TrapFocus(props) {
};

const loopFocus = (nativeEvent) => {
// 9 = Tab
if (disableEnforceFocus || !isEnabled() || nativeEvent.keyCode !== 9) {
if (disableEnforceFocus || !isEnabled() || nativeEvent.key !== 'Tab') {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ describe('<TrapFocus />', () => {
);

fireEvent.keyDown(screen.getByTestId('modal'), {
keyCode: 13, // Enter
key: 'Enter',
});
fireEvent.keyDown(screen.getByTestId('modal'), {
keyCode: 9, // Tab
key: 'Tab',
});

expect(document.querySelector('[data-test="sentinelStart"]')).toHaveFocus();

initialFocus.focus();
fireEvent.keyDown(screen.getByTestId('modal'), {
keyCode: 9, // Tab
key: 'Tab',
shiftKey: true,
});

Expand Down

0 comments on commit 58a899e

Please sign in to comment.