diff --git a/package.json b/package.json index 1da0a90b01..d2e7786bed 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "filesize": "3.5.6", "flux": "2.1.1", "focus-trap-react": "^3.0.5", + "focus-visible": "^5.0.2", "fuse.js": "^2.2.0", "gemini-scrollbar": "github:matrix-org/gemini-scrollbar#91e1e566", "gfm.css": "^1.1.1", diff --git a/res/css/views/elements/_AccessibleButton.scss b/res/css/views/elements/_AccessibleButton.scss index 0c081ec0d5..f3afef284f 100644 --- a/res/css/views/elements/_AccessibleButton.scss +++ b/res/css/views/elements/_AccessibleButton.scss @@ -18,7 +18,7 @@ limitations under the License. cursor: pointer; } -.mx_AccessibleButton:focus { +.mx_AccessibleButton:focus:not(.focus-visible) { outline: 0; } diff --git a/src/components/structures/ContextualMenu.js b/src/components/structures/ContextualMenu.js index 0f4d0b38d4..04314e5a4e 100644 --- a/src/components/structures/ContextualMenu.js +++ b/src/components/structures/ContextualMenu.js @@ -21,6 +21,7 @@ import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import {focusCapturedRef} from "../../utils/Accessibility"; +import {KeyCode} from "../../Keyboard"; // Shamelessly ripped off Modal.js. There's probably a better way // of doing reusable widgets like dialog boxes & menus where we go and @@ -67,7 +68,7 @@ export default class ContextualMenu extends React.Component { // on resize callback windowResize: PropTypes.func, // method to close menu - closeMenu: PropTypes.func, + closeMenu: PropTypes.func.isRequired, }; constructor() { @@ -114,6 +115,14 @@ export default class ContextualMenu extends React.Component { } } + _onKeyDown = (ev) => { + if (ev.keyCode === KeyCode.ESCAPE) { + ev.stopPropagation(); + ev.preventDefault(); + this.props.closeMenu(); + } + }; + render() { const position = {}; let chevronFace = null; @@ -210,7 +219,7 @@ export default class ContextualMenu extends React.Component { // FIXME: If a menu uses getDefaultProps it clobbers the onFinished // property set here so you can't close the menu from a button click! - return