Merge pull request #3454 from matrix-org/travis/focus
Focus context menus so screen readers can find them
This commit is contained in:
commit
d7a1116880
1 changed files with 5 additions and 1 deletions
|
@ -20,6 +20,7 @@ import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import {focusCapturedRef} from "../../utils/Accessibility";
|
||||||
|
|
||||||
// Shamelessly ripped off Modal.js. There's probably a better way
|
// Shamelessly ripped off Modal.js. There's probably a better way
|
||||||
// of doing reusable widgets like dialog boxes & menus where we go and
|
// of doing reusable widgets like dialog boxes & menus where we go and
|
||||||
|
@ -83,6 +84,9 @@ export default class ContextualMenu extends React.Component {
|
||||||
// We don't need to clean up when unmounting, so ignore
|
// We don't need to clean up when unmounting, so ignore
|
||||||
if (!element) return;
|
if (!element) return;
|
||||||
|
|
||||||
|
// For screen readers to find the thing
|
||||||
|
focusCapturedRef(element);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
contextMenuRect: element.getBoundingClientRect(),
|
contextMenuRect: element.getBoundingClientRect(),
|
||||||
});
|
});
|
||||||
|
@ -206,7 +210,7 @@ export default class ContextualMenu extends React.Component {
|
||||||
// FIXME: If a menu uses getDefaultProps it clobbers the onFinished
|
// FIXME: If a menu uses getDefaultProps it clobbers the onFinished
|
||||||
// property set here so you can't close the menu from a button click!
|
// property set here so you can't close the menu from a button click!
|
||||||
return <div className={className} style={{...position, ...wrapperStyle}}>
|
return <div className={className} style={{...position, ...wrapperStyle}}>
|
||||||
<div className={menuClasses} style={menuStyle} ref={this.collectContextMenuRect}>
|
<div className={menuClasses} style={menuStyle} ref={this.collectContextMenuRect} tabIndex={0}>
|
||||||
{ chevron }
|
{ chevron }
|
||||||
<ElementClass {...props} onFinished={props.closeMenu} onResize={props.windowResize} />
|
<ElementClass {...props} onFinished={props.closeMenu} onResize={props.windowResize} />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue