-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,011 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-clickable": major | ||
"@khanacademy/wonder-blocks-dropdown": major | ||
"@khanacademy/wonder-blocks-core": major | ||
--- | ||
|
||
Fixes keyboard tests in Dropdown and Clickable with specific key events. We now check `event.key` instead of `event.which` or `event.keyCode` to remove deprecated event properties and match the keys returned from Testing Library/userEvent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-dropdown": major | ||
--- | ||
|
||
1. Updates dropdown openers for SingleSelect and MultiSelect to use `role="combobox"` instead of `button`. | ||
2. SingleSelect and MultiSelect should have a paired `<label>` element or `aria-label` attribute for accessibility. They no longer fall back to text content for labeling, as those contents are now used as combobox values. | ||
3. Changes the type names for custom label objects from `Labels` to `LabelsValues` and `SingleSelectLabels` to `SingleSelectLabelsValues`, respectively. |
46 changes: 46 additions & 0 deletions
46
__docs__/wonder-blocks-dropdown/multi-select.accessibility.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {Meta, Story, Canvas} from "@storybook/blocks"; | ||
import * as MultiSelectAccessibilityStories from './multi-select.accessibility.stories'; | ||
|
||
import {OptionItem, MultiSelect} from "@khanacademy/wonder-blocks-dropdown"; | ||
import {View} from "@khanacademy/wonder-blocks-core"; | ||
import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field"; | ||
|
||
<Meta of={MultiSelectAccessibilityStories} /> | ||
|
||
# Accessibility | ||
|
||
## Using `LabeledField` with `MultiSelect` | ||
|
||
To associate a `MultiSelect` with another visible element (e.g. a `<label>`), | ||
wrap it in a `LabeledField` component. The label will apply to the `MultiSelect` | ||
opener. With `LabeledField`, you can supply label text (or a JSX node) | ||
using the `label` prop to generate a paired `<label>` element. It comes with | ||
field validation and other features baked in! | ||
|
||
If for some reason you can't use `LabeledField` for a visible label, you can still | ||
make `MultiSelect` accessible in a screen reader by associating it with `<label for="">`. | ||
Pass the `id` of the `MultiSelect` to the `for` attribute. | ||
|
||
Alternatively, you can create an accessible name for `MultiSelect` using `aria-labelledby`. | ||
Put `aria-labelledby` on `MultiSelect` pointing to the `id` of any other element. | ||
It won't give you the same enhanced click target as a paired `<label>`, but it still | ||
helps to create a more accessible experience. | ||
|
||
<Canvas of={MultiSelectAccessibilityStories.UsingAriaAttributes} /> | ||
|
||
## Using `aria-label` for the opener and/or child options | ||
|
||
A visible label with `<LabeledField>` is preferred. However, for specific cases | ||
where the `MultiSelect` is not paired with a `LabeledField` or other visible | ||
`<label>` element, you **must** supply an `aria-label` attribute for an | ||
accessible name on the opener. | ||
|
||
This will ensure the `MultiSelect` as a whole has a name that describes its purpose. | ||
|
||
Also, if you need screen readers to understand relevant information on | ||
option items, you can use `aria-label` on each item. e.g. You can use it to let | ||
screen readers know the current selected/unselected status of the item when it | ||
receives focus. This can be useful when the options contain icons or other information | ||
that would need to be omitted from the visible label. | ||
|
||
<Canvas of={MultiSelectAccessibilityStories.UsingOpenerAriaLabel} /> |
131 changes: 131 additions & 0 deletions
131
__docs__/wonder-blocks-dropdown/multi-select.accessibility.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import * as React from "react"; | ||
import magnifyingGlassIcon from "@phosphor-icons/core/regular/magnifying-glass.svg"; | ||
import {OptionItem, MultiSelect} from "@khanacademy/wonder-blocks-dropdown"; | ||
import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field"; | ||
import {View} from "@khanacademy/wonder-blocks-core"; | ||
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; | ||
|
||
export default { | ||
title: "Packages / Dropdown / MultiSelect / Accessibility", | ||
component: MultiSelect, | ||
|
||
// Disables chromatic testing for these stories. | ||
parameters: { | ||
previewTabs: { | ||
canvas: { | ||
hidden: true, | ||
}, | ||
}, | ||
|
||
viewMode: "docs", | ||
|
||
chromatic: { | ||
disableSnapshot: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const MultiSelectAccessibility = () => ( | ||
<View> | ||
<LabeledField | ||
label="Associated label element" | ||
field={ | ||
<MultiSelect selectedValues={["one"]} onChange={() => {}}> | ||
<OptionItem label="First element" value="one" /> | ||
<OptionItem label="Second element" value="two" /> | ||
</MultiSelect> | ||
} | ||
/> | ||
</View> | ||
); | ||
|
||
export const UsingAriaAttributes = { | ||
render: MultiSelectAccessibility.bind({}), | ||
name: "Using LabeledField", | ||
}; | ||
|
||
const MultiSelectAriaLabel = () => ( | ||
<View> | ||
<MultiSelect | ||
aria-label="Class options" | ||
id="unique-single-select" | ||
selectedValues={["one"]} | ||
onChange={() => {}} | ||
> | ||
<OptionItem | ||
label="First element" | ||
aria-label="First element, selected" | ||
value="one" | ||
/> | ||
<OptionItem | ||
label="Second element" | ||
aria-label="Second element, unselelected" | ||
value="two" | ||
/> | ||
</MultiSelect> | ||
</View> | ||
); | ||
|
||
export const UsingOpenerAriaLabel = { | ||
render: MultiSelectAriaLabel.bind({}), | ||
name: "Using aria-label attributes", | ||
}; | ||
|
||
const MultiSelectCustomOpenerLabeledField = () => { | ||
return ( | ||
<View> | ||
<LabeledField | ||
label="Search" | ||
field={ | ||
<MultiSelect | ||
onChange={() => {}} | ||
opener={(eventState: any) => ( | ||
<button onClick={() => {}}> | ||
<PhosphorIcon | ||
icon={magnifyingGlassIcon} | ||
size="medium" | ||
/> | ||
</button> | ||
)} | ||
> | ||
<OptionItem label="item 1" value="1" /> | ||
<OptionItem label="item 2" value="2" /> | ||
<OptionItem label="item 3" value="3" /> | ||
</MultiSelect> | ||
} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
export const UsingCustomOpenerLabeledField = { | ||
render: MultiSelectCustomOpenerLabeledField.bind({}), | ||
name: "Using custom opener in a LabeledField", | ||
}; | ||
|
||
const MultiSelectCustomOpenerLabel = () => { | ||
return ( | ||
<View> | ||
<MultiSelect | ||
onChange={() => {}} | ||
opener={(eventState: any) => ( | ||
<button aria-label="Search button" onClick={() => {}}> | ||
<PhosphorIcon | ||
icon={magnifyingGlassIcon} | ||
size="medium" | ||
/> | ||
</button> | ||
)} | ||
> | ||
<OptionItem label="item 1" value="1" /> | ||
<OptionItem label="item 2" value="2" /> | ||
<OptionItem label="item 3" value="3" /> | ||
</MultiSelect> | ||
</View> | ||
); | ||
}; | ||
|
||
export const UsingCustomOpenerAriaLabel = { | ||
render: MultiSelectCustomOpenerLabel.bind({}), | ||
name: "Using aria-label on custom opener", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.