chore: improve accessibility

This commit is contained in:
Corbin Crutchley
2023-07-24 05:41:16 -07:00
parent 29a9440348
commit b0c04f6220

View File

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