From c37e27f03d2ed066c7bfea8c50ead8835657e57d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 26 Sep 2019 14:52:20 +0100 Subject: [PATCH] Improve a11y: + Close context menu on escape + Use AccessibleButtons for more things (Context Menus and TabbedView) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ContextualMenu.js | 13 ++- src/components/structures/TabbedView.js | 25 ++---- .../structures/TopLeftMenuButton.js | 3 +- .../GroupInviteTileContextMenu.js | 6 +- .../views/context_menus/MessageContextMenu.js | 87 ++++++++----------- .../context_menus/RoomTileContextMenu.js | 46 ++++++---- 6 files changed, 86 insertions(+), 94 deletions(-) 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