[improvement] Switch: improve accessibility

This commit is contained in:
陈嘉涵
2019-05-25 12:17:02 +08:00
parent a7e346ca0f
commit 6cc14d8651
8 changed files with 21 additions and 16 deletions
+6 -2
View File
@@ -31,6 +31,8 @@ function Switch(
inactiveValue
} = props;
const checked = value === activeValue;
const switchStyle = {
fontSize: size,
backgroundColor: value ? activeColor : inactiveColor
@@ -40,7 +42,7 @@ function Switch(
function onClick() {
if (!disabled && !loading) {
const newValue = value === activeValue ? inactiveValue : activeValue;
const newValue = checked ? inactiveValue : activeValue;
emit(ctx, 'input', newValue);
emit(ctx, 'change', newValue);
}
@@ -49,10 +51,12 @@ function Switch(
return (
<div
class={bem({
on: value === activeValue,
on: checked,
disabled
})}
role="switch"
style={switchStyle}
aria-checked={String(checked)}
onClick={onClick}
{...inherit(ctx)}
>