[improvement] Switch: improve accessibility
This commit is contained in:
@@ -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)}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user