tidy ToggleSwitch

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2019-10-08 12:18:44 +01:00
parent a782baf510
commit a03e9e7a4f
1 changed files with 5 additions and 7 deletions

View File

@ -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);
}
};