diff --git a/.changeset/ninety-dogs-push.md b/.changeset/ninety-dogs-push.md new file mode 100644 index 000000000..935fd5c00 --- /dev/null +++ b/.changeset/ninety-dogs-push.md @@ -0,0 +1,17 @@ +--- +"@khanacademy/wonder-blocks-dropdown": minor +--- + +Improves support for providing ids to the opener and dropdown elements. These ids are auto-generated if they are not provided. + +Also applies attributes to elements automatically for improved accessibility (`aria-controls`, `aria-haspopup`, `aria-expanded`). + +- `ActionMenu` + - Adds new `dropdownId` and `id` props. If these are not provided, these ids will be generated automatically + - `aria-controls` is set to the dropdown id for both default and custom openers + - Ensure `aria-haspopup` and `aria-expanded` attributes are set on both default and custom openers +- `SingleSelect` and `MultiSelect` + - Adds new `dropdownId` prop. If this is not provided, an id will be generated automatically + - If the `id` prop is not provided, an id for the component is now generated automatically + - `aria-controls` is set to the dropdown id for both default and custom openers + - Ensure `id`, `aria-haspopup` and `aria-expanded` attributes are set on both default and custom openers diff --git a/__docs__/wonder-blocks-dropdown/action-menu.stories.tsx b/__docs__/wonder-blocks-dropdown/action-menu.stories.tsx index 9618c9c80..4aef5bc08 100644 --- a/__docs__/wonder-blocks-dropdown/action-menu.stories.tsx +++ b/__docs__/wonder-blocks-dropdown/action-menu.stories.tsx @@ -358,6 +358,9 @@ export const Controlled: StoryComponentType = { * * **Note:** If you need to use a custom ID for testing the opener, make sure to * pass the testId prop inside the opener component/element. + * + * **Accessibility:** When a custom opener is used, the following attributes are + * added automatically: `aria-expanded`, `aria-haspopup`, and `aria-controls`. */ export const CustomOpener: StoryComponentType = { @@ -375,6 +378,7 @@ export const CustomOpener: StoryComponentType = { hovered && styles.hovered, pressed && styles.pressed, ]} + role="button" > {text} diff --git a/__docs__/wonder-blocks-dropdown/base-select.argtypes.ts b/__docs__/wonder-blocks-dropdown/base-select.argtypes.ts index de194e6ba..d15d74d64 100644 --- a/__docs__/wonder-blocks-dropdown/base-select.argtypes.ts +++ b/__docs__/wonder-blocks-dropdown/base-select.argtypes.ts @@ -117,8 +117,22 @@ const argTypes: ArgTypes = { control: {type: "text"}, description: `Unique identifier attached to the field control. If used, we need to guarantee that the ID is unique within everything - rendered on a page. Used to match \`