You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-19 05:22:13 +03:00
Allow keyboard control even without a screen reader
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import classNames from "classnames";
|
||||
import {KeyCode} from "../../../Keyboard";
|
||||
|
||||
export default class ToggleSwitch extends React.Component {
|
||||
static propTypes = {
|
||||
@@ -44,10 +45,7 @@ export default class ToggleSwitch extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
_onClick = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
_toggle = () => {
|
||||
if (this.props.disabled) return;
|
||||
|
||||
const newState = !this.state.checked;
|
||||
@@ -57,6 +55,22 @@ export default class ToggleSwitch extends React.Component {
|
||||
}
|
||||
};
|
||||
|
||||
_onClick = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
this._toggle();
|
||||
};
|
||||
|
||||
_onKeyDown = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) {
|
||||
this._toggle();
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {checked, disabled, onChange, ...props} = this.props;
|
||||
@@ -71,6 +85,7 @@ export default class ToggleSwitch extends React.Component {
|
||||
{...props}
|
||||
className={classes}
|
||||
onClick={this._onClick}
|
||||
onKeyDown={this._onKeyDown}
|
||||
role="checkbox"
|
||||
aria-checked={this.state.checked}
|
||||
aria-disabled={disabled}
|
||||
|
||||
Reference in New Issue
Block a user