tidy ToggleSwitch
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
a782baf510
commit
a03e9e7a4f
1 changed files with 5 additions and 7 deletions
|
@ -23,23 +23,21 @@ import {KeyCode} from "../../../Keyboard";
|
||||||
|
|
||||||
// Controlled Toggle Switch element
|
// Controlled Toggle Switch element
|
||||||
const ToggleSwitch = ({checked, disabled=false, onChange, ...props}) => {
|
const ToggleSwitch = ({checked, disabled=false, onChange, ...props}) => {
|
||||||
const _toggle = () => {
|
|
||||||
if (disabled) return;
|
|
||||||
onChange(!checked);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _onClick = (e) => {
|
const _onClick = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
_toggle();
|
if (disabled) return;
|
||||||
|
|
||||||
|
onChange(!checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onKeyDown = (e) => {
|
const _onKeyDown = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (disabled) return;
|
||||||
|
|
||||||
if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) {
|
if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) {
|
||||||
_toggle();
|
onChange(!checked);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue