You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-17 17:42:41 +03:00
tidy ToggleSwitch
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -23,23 +23,21 @@ import {KeyCode} from "../../../Keyboard";
|
||||
|
||||
// Controlled Toggle Switch element
|
||||
const ToggleSwitch = ({checked, disabled=false, onChange, ...props}) => {
|
||||
const _toggle = () => {
|
||||
if (disabled) return;
|
||||
onChange(!checked);
|
||||
};
|
||||
|
||||
const _onClick = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
_toggle();
|
||||
if (disabled) return;
|
||||
|
||||
onChange(!checked);
|
||||
};
|
||||
|
||||
const _onKeyDown = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
if (disabled) return;
|
||||
|
||||
if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) {
|
||||
_toggle();
|
||||
onChange(!checked);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user