mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-06 12:57:44 +00:00
chore: improve accessibility
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import { VNode } from "preact";
|
import { VNode } from "preact";
|
||||||
import { CheckboxBox } from "components/checkbox-box/checkbox-box";
|
import { CheckboxBox } from "components/checkbox-box/checkbox-box";
|
||||||
import { VisuallyHidden } from "react-aria";
|
import { useCheckbox, VisuallyHidden } from "react-aria";
|
||||||
import style from "./filter-section-item.module.scss";
|
import style from "./filter-section-item.module.scss";
|
||||||
|
import { useToggleState } from "react-stately";
|
||||||
|
import { useRef } from "preact/hooks";
|
||||||
|
|
||||||
interface FilterSectionItemProps {
|
interface FilterSectionItemProps {
|
||||||
icon: VNode<any>;
|
icon: VNode<any>;
|
||||||
@@ -18,12 +20,23 @@ export const FilterSectionItem = ({
|
|||||||
selected,
|
selected,
|
||||||
onChange,
|
onChange,
|
||||||
}: FilterSectionItemProps) => {
|
}: FilterSectionItemProps) => {
|
||||||
|
const props = {
|
||||||
|
isSelected: selected,
|
||||||
|
onChange: onChange,
|
||||||
|
};
|
||||||
|
|
||||||
|
const state = useToggleState(props);
|
||||||
|
|
||||||
|
const ref = useRef(null);
|
||||||
|
const { inputProps } = useCheckbox(props, state, ref);
|
||||||
|
const isSelected = state.isSelected;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CheckboxBox
|
<CheckboxBox
|
||||||
selected={selected}
|
selected={isSelected}
|
||||||
wrapper={(children) => (
|
wrapper={(children) => (
|
||||||
<label
|
<label
|
||||||
class={`${style.containerLabel} ${selected ? style.selected : ""}`}
|
class={`${style.containerLabel} ${isSelected ? style.selected : ""}`}
|
||||||
>
|
>
|
||||||
<span aria-hidden={true} class={style.iconContainer}>
|
<span aria-hidden={true} class={style.iconContainer}>
|
||||||
{icon}
|
{icon}
|
||||||
@@ -33,11 +46,7 @@ export const FilterSectionItem = ({
|
|||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
<VisuallyHidden>
|
<VisuallyHidden>
|
||||||
<input
|
<input {...inputProps} ref={ref} />
|
||||||
type="checkbox"
|
|
||||||
onChange={(e) => onChange()}
|
|
||||||
checked={selected}
|
|
||||||
/>
|
|
||||||
</VisuallyHidden>
|
</VisuallyHidden>
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user