Skip to content

Commit

Permalink
Remove value prefix on Select combobox accessible name
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmacknz committed Nov 20, 2023
1 parent 391c220 commit 204169f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-wombats-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": patch
---

Remove value prefix on Select combobox accessible name
20 changes: 9 additions & 11 deletions packages/components/src/__future__/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("<Select />", () => {
it("makes sure the menu to be labelled by trigger", () => {
const { getByRole } = render(<SelectWrapper selectedKey="batch-brew" />)
const menu = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})
expect(menu).toHaveTextContent("Batch brew")
})
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("<Select />", () => {
/>
)
const trigger = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})
await user.click(trigger)
await waitFor(() => {
Expand All @@ -93,7 +93,7 @@ describe("<Select />", () => {
<SelectWrapper selectedKey="batch-brew" />
)
const trigger = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})
await user.click(trigger)
await waitFor(() => {
Expand All @@ -108,7 +108,7 @@ describe("<Select />", () => {
<SelectWrapper selectedKey="batch-brew" defaultOpen />
)
const trigger = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})

await user.click(trigger)
Expand Down Expand Up @@ -147,7 +147,7 @@ describe("<Select />", () => {
<SelectWrapper selectedKey="batch-brew" />
)
const trigger = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})
await user.tab()
await waitFor(() => {
Expand All @@ -160,7 +160,7 @@ describe("<Select />", () => {
<SelectWrapper selectedKey="batch-brew" />
)
const trigger = getByRole("combobox", {
name: "Batch brew Mock Label",
name: "Mock Label",
})
await user.tab()
await waitFor(() => {
Expand Down Expand Up @@ -305,9 +305,7 @@ describe("<Select />", () => {
})
await user.keyboard("{Enter}")

await user.click(
getByRole("combobox", { name: "Short black Mock Label" })
)
await user.click(getByRole("combobox", { name: "Mock Label" }))
await waitFor(() => {
expect(
getByRole("option", { name: "Short black", selected: true })
Expand All @@ -320,7 +318,7 @@ describe("<Select />", () => {
const { getByRole } = render(
<SelectWrapper onSelectionChange={spy} defaultOpen />
)
const trigger = getByRole("combobox", { name: "Select Mock Label" })
const trigger = getByRole("combobox", { name: "Mock Label" })

await user.tab()
await waitFor(() => {
Expand All @@ -332,7 +330,7 @@ describe("<Select />", () => {
await user.keyboard("{Enter}")
await waitFor(() => {
expect(spy).toHaveBeenCalledTimes(1)
expect(trigger).toHaveAccessibleName("Short black Mock Label")
expect(trigger).toHaveAccessibleName("Mock Label")
})
})
})
Expand Down
12 changes: 11 additions & 1 deletion packages/components/src/__future__/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,23 @@ export const Select = <Option extends SelectOption = SelectOption>({

const {
labelProps,
triggerProps,
triggerProps: reactAriaTriggerProps,
valueProps,
menuProps,
errorMessageProps,
descriptionProps,
} = useSelect(ariaSelectProps, state, triggerRef)

// Hack incoming:
// react-aria/useSelect wants to prefix the combobox's accessible name with the value of the select.
// We use role=combobox, meaning screen readers will read the value.
// So we're modifying the `aria-labelledby` property to remove the value element id.
// Issue: https://github.com/adobe/react-spectrum/issues/4091
const triggerProps = {
...reactAriaTriggerProps,
"aria-labelledby": reactAriaTriggerProps["aria-labelledby"]?.split(" ")[1],
}

const { buttonProps } = useButton(triggerProps, triggerRef)
const selectToggleProps = {
...buttonProps,
Expand Down

0 comments on commit 204169f

Please sign in to comment.