add roles and aria-selected to the product page's swatches

Currently for a user with a screen reader it would be near impossible to use this page. This change will read clearly what the swatch is and for what group it belongs.
This commit is contained in:
Brendan Offer 2021-04-12 20:55:32 -04:00
parent 936f149fcc
commit 1c3bd853fb
2 changed files with 4 additions and 2 deletions

View File

@ -104,7 +104,7 @@ const ProductView: FC<Props> = ({ product }) => {
{product.options?.map((opt) => (
<div className="pb-4" key={opt.displayName}>
<h2 className="uppercase font-medium">{opt.displayName}</h2>
<div className="flex flex-row py-4">
<div role="listbox" className="flex flex-row py-4">
{opt.values.map((v, i: number) => {
const active = (choices as any)[
opt.displayName.toLowerCase()

View File

@ -39,7 +39,9 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
<Button
className={rootClassName}
style={color ? { backgroundColor: color } : {}}
aria-label="Variant Swatch"
role="option"
aria-label={`${variant} ${label}`}
aria-selected={active}
{...props}
>
{variant === 'color' && active && (