diff --git a/site/src/components/Combobox/Combobox.tsx b/site/src/components/Combobox/Combobox.tsx index cf2d2b6b29f..1515924795e 100644 --- a/site/src/components/Combobox/Combobox.tsx +++ b/site/src/components/Combobox/Combobox.tsx @@ -81,12 +81,6 @@ type ComboboxButtonProps = Omit, "children"> & { width?: number; selectedOption?: SelectFilterOption; placeholder?: string; - /** - * Visible label rendered before the value. It also sets the accessible name - * to `${label}: ${value}`, so don't pass `aria-label` with it: a caller's - * `aria-label` overrides that name and drops the visible label from it. - */ - label?: string; }; export const ComboboxButton = ({ @@ -94,14 +88,13 @@ export const ComboboxButton = ({ width, selectedOption, placeholder, - label, ref, ...props }: ComboboxButtonProps) => { const { open: isPopoverOpen } = useCombobox(); - const valueRef = useRef(null); + const labelRef = useRef(null); const [isTooltipOpen, setIsTooltipOpen] = useState(false); - const value = selectedOption?.label ?? placeholder; + const label = selectedOption?.label ?? placeholder; return ( { - const span = valueRef.current; + const span = labelRef.current; setIsTooltipOpen( open && !isPopoverOpen && @@ -128,33 +121,20 @@ export const ComboboxButton = ({ style={{ flexBasis: width }} variant="outline" ref={ref} - aria-label={label && (value ? `${label}: ${value}` : label)} {...props} > - {label && ( - <> - - {label}: - {" "} - - )} - {selectedOption?.startIcon && ( - // The value text already names the selection. - - )} + {selectedOption?.startIcon} - {value} + {label} - {value} + {label} ); diff --git a/site/src/components/Filter/SelectFilter.stories.tsx b/site/src/components/Filter/SelectFilter.stories.tsx index 24f27f5f2cc..eda20f379df 100644 --- a/site/src/components/Filter/SelectFilter.stories.tsx +++ b/site/src/components/Filter/SelectFilter.stories.tsx @@ -17,7 +17,7 @@ const meta: Meta = { component: SelectFilter, args: { options, - label: "Option", + placeholder: "All options", }, decorators: [withDesktopViewport], render: function SelectFilterWithState(args) { @@ -158,7 +158,7 @@ export const UnselectingOption: Story = { // Click the already-selected option to unselect it (toggle behavior) const option = screen.getByRole("option", { name: /Option 26/ }); await userEvent.click(option); - await expect(button).toHaveAccessibleName("Option: All"); + await expect(button).toHaveTextContent("All options"); }, }; diff --git a/site/src/components/Filter/SelectFilter.test.tsx b/site/src/components/Filter/SelectFilter.test.tsx index 1f0b9e26a40..c2e7159fec7 100644 --- a/site/src/components/Filter/SelectFilter.test.tsx +++ b/site/src/components/Filter/SelectFilter.test.tsx @@ -14,7 +14,8 @@ it("selects an option with the keyboard alone", async () => { const onSelect = vi.fn(); renderComponent( { ]; renderComponent( , ); - await user.click(screen.getByRole("button", { name: "Status: Dormant" })); + await user.click(screen.getByRole("button", { name: "Select a status" })); await screen.findByRole("option", { name: "Active" }); expect(screen.getByRole("option", { selected: true })).toHaveAccessibleName( "Dormant", @@ -57,7 +59,8 @@ it("names the search input with the search label", async () => { const onValueChange = vi.fn(); renderComponent( { />, ); - await user.click(screen.getByRole("button", { name: "Status: All" })); + await user.click(screen.getByRole("button", { name: "Select a status" })); await user.type( await screen.findByRole("combobox", { name: "Search status" }), "a", @@ -87,15 +90,14 @@ const renderLongLabelFilter = (scrollWidth: number) => { vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(100); renderComponent( , ); - return screen.getByRole("button", { - name: `Organization: ${longOption.label}`, - }); + return screen.getByRole("button", { name: "Select an organization" }); }; it("describes the focused trigger with its full label when truncated", async () => { diff --git a/site/src/components/Filter/SelectFilter.tsx b/site/src/components/Filter/SelectFilter.tsx index 77a71ca23b2..69f3b039982 100644 --- a/site/src/components/Filter/SelectFilter.tsx +++ b/site/src/components/Filter/SelectFilter.tsx @@ -22,8 +22,10 @@ export type SelectFilterOption = { type SelectFilterProps = { options: SelectFilterOption[] | undefined; selectedOption?: SelectFilterOption; - // Visible label shown before the value. It is also part of the name. + // Used to add a accessibility label to the select label: string; + // Used when there is no option selected + placeholder: string; // Used to customize the empty state message emptyText?: string; onSelect: (option: SelectFilterOption | undefined) => void; @@ -39,6 +41,7 @@ export const SelectFilter: React.FC = ({ options, selectedOption, onSelect, + placeholder, emptyText = "No options found", width = BASE_WIDTH, selectFilterSearch, @@ -54,10 +57,10 @@ export const SelectFilter: React.FC = ({