Commit d4d515b9 authored by Kyle Keating's avatar Kyle Keating

Replace all keypress events with the keydown event

keypress is deprecated
https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event
parent 4a0013ad
...@@ -66,7 +66,7 @@ export default function useElementShouldClose( ...@@ -66,7 +66,7 @@ export default function useElementShouldClose(
} }
// Close element when user presses Escape key, regardless of focus. // Close element when user presses Escape key, regardless of focus.
const removeKeypressListener = listen(document.body, ['keydown'], event => { const removeKeyDownListener = listen(document.body, ['keydown'], event => {
if (event.key === 'Escape') { if (event.key === 'Escape') {
handleClose(); handleClose();
} }
...@@ -101,7 +101,7 @@ export default function useElementShouldClose( ...@@ -101,7 +101,7 @@ export default function useElementShouldClose(
); );
return () => { return () => {
removeKeypressListener(); removeKeyDownListener();
removeClickListener(); removeClickListener();
removeFocusListener(); removeFocusListener();
}; };
......
...@@ -293,7 +293,7 @@ export default function MarkdownEditor({ ...@@ -293,7 +293,7 @@ export default function MarkdownEditor({
dir="auto" dir="auto"
ref={input} ref={input}
onClick={e => e.stopPropagation()} onClick={e => e.stopPropagation()}
onKeydown={handleKeyDown} onKeyDown={handleKeyDown}
onInput={e => onEditText({ text: e.target.value })} onInput={e => onEditText({ text: e.target.value })}
value={text} value={text}
/> />
......
...@@ -94,7 +94,7 @@ export default function Menu({ ...@@ -94,7 +94,7 @@ export default function Menu({
const stopPropagation = e => e.stopPropagation(); const stopPropagation = e => e.stopPropagation();
// It should also close if the user presses a key which activates menu items. // It should also close if the user presses a key which activates menu items.
const handleMenuKeyPress = event => { const handleMenuKeyDown = event => {
if (event.key === 'Enter' || event.key === ' ') { if (event.key === 'Enter' || event.key === ' ') {
closeMenu(); closeMenu();
} }
...@@ -154,7 +154,7 @@ export default function Menu({ ...@@ -154,7 +154,7 @@ export default function Menu({
role="menu" role="menu"
tabIndex="-1" tabIndex="-1"
onClick={closeMenu} onClick={closeMenu}
onKeyPress={handleMenuKeyPress} onKeyDown={handleMenuKeyDown}
> >
{children} {children}
</div> </div>
......
...@@ -111,7 +111,7 @@ describe('Menu', () => { ...@@ -111,7 +111,7 @@ describe('Menu', () => {
const wrapper = createMenu({ defaultOpen: true }); const wrapper = createMenu({ defaultOpen: true });
act(() => { act(() => {
const event = new Event('keypress'); const event = new Event('keydown');
event.key = 'a'; event.key = 'a';
document.body.dispatchEvent(event); document.body.dispatchEvent(event);
}); });
...@@ -140,17 +140,17 @@ describe('Menu', () => { ...@@ -140,17 +140,17 @@ describe('Menu', () => {
shouldClose: true, shouldClose: true,
}, },
{ {
eventType: 'keypress', eventType: 'keydown',
key: 'Enter', key: 'Enter',
shouldClose: true, shouldClose: true,
}, },
{ {
eventType: 'keypress', eventType: 'keydown',
key: ' ', key: ' ',
shouldClose: true, shouldClose: true,
}, },
{ {
eventType: 'keypress', eventType: 'keydown',
key: 'a', key: 'a',
shouldClose: false, shouldClose: false,
}, },
......
...@@ -15,7 +15,7 @@ export function onActivate(role, handler) { ...@@ -15,7 +15,7 @@ export function onActivate(role, handler) {
onClick: handler, onClick: handler,
// Support keyboard activation. // Support keyboard activation.
onKeypress: event => { onKeyDown: event => {
if (event.key === 'Enter' || event.key === ' ') { if (event.key === 'Enter' || event.key === ' ') {
handler(event); handler(event);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment