revert(site/src/components): drop the unused SelectFilter and ComboboxButton label changes
This commit is contained in:
1 parent
1593bb43b9
commit
d6b4bfdce5
4 files changed
+26
-41
No files matched your search
@@ -81,12 +81,6 @@ type ComboboxButtonProps = Omit<React.ComponentProps<"button">, "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<HTMLSpanElement>(null);
|
||||
const labelRef = useRef<HTMLSpanElement>(null);
|
||||
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
|
||||
const value = selectedOption?.label ?? placeholder;
|
||||
const label = selectedOption?.label ?? placeholder;
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
@@ -110,7 +103,7 @@ export const ComboboxButton = ({
|
||||
// applied after mount still reveals the full label. Stays closed while
|
||||
// the popover is open so it never covers the list.
|
||||
onOpenChange={(open) => {
|
||||
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 && (
|
||||
<>
|
||||
<span className="shrink-0 text-content-secondary">
|
||||
{label}:
|
||||
</span>{" "}
|
||||
</>
|
||||
)}
|
||||
{selectedOption?.startIcon && (
|
||||
// The value text already names the selection.
|
||||
<span aria-hidden="true" className="contents">
|
||||
{selectedOption.startIcon}
|
||||
</span>
|
||||
)}
|
||||
{selectedOption?.startIcon}
|
||||
<span
|
||||
ref={valueRef}
|
||||
ref={labelRef}
|
||||
className="text-left block overflow-hidden text-ellipsis grow"
|
||||
>
|
||||
{value}
|
||||
{label}
|
||||
</span>
|
||||
<ChevronDownIcon className="size-icon-sm" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" align="start" className="max-w-65">
|
||||
{value}
|
||||
{label}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ const meta: Meta<typeof SelectFilter> = {
|
||||
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");
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ it("selects an option with the keyboard alone", async () => {
|
||||
const onSelect = vi.fn();
|
||||
renderComponent(
|
||||
<SelectFilter
|
||||
label="Status"
|
||||
label="Select a status"
|
||||
placeholder="All statuses"
|
||||
options={[
|
||||
{ label: "Active", value: "active" },
|
||||
{ label: "Dormant", value: "dormant" },
|
||||
@@ -38,14 +39,15 @@ it("marks the chosen option as selected", async () => {
|
||||
];
|
||||
renderComponent(
|
||||
<SelectFilter
|
||||
label="Status"
|
||||
label="Select a status"
|
||||
placeholder="All statuses"
|
||||
options={options}
|
||||
selectedOption={options[1]}
|
||||
onSelect={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
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(
|
||||
<SelectFilter
|
||||
label="Status"
|
||||
label="Select a status"
|
||||
placeholder="All statuses"
|
||||
options={[{ label: "Active", value: "active" }]}
|
||||
onSelect={vi.fn()}
|
||||
searchLabel="Search status"
|
||||
@@ -70,7 +73,7 @@ it("names the search input with the search label", async () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
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(
|
||||
<SelectFilter
|
||||
label="Organization"
|
||||
label="Select an organization"
|
||||
placeholder="All organizations"
|
||||
options={[longOption]}
|
||||
selectedOption={longOption}
|
||||
onSelect={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
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 () => {
|
||||
|
||||
@@ -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<SelectFilterProps> = ({
|
||||
options,
|
||||
selectedOption,
|
||||
onSelect,
|
||||
placeholder,
|
||||
emptyText = "No options found",
|
||||
width = BASE_WIDTH,
|
||||
selectFilterSearch,
|
||||
@@ -54,10 +57,10 @@ export const SelectFilter: React.FC<SelectFilterProps> = ({
|
||||
<ComboboxTrigger asChild>
|
||||
<ComboboxButton
|
||||
selectedOption={selectedOption}
|
||||
placeholder="All"
|
||||
placeholder={placeholder}
|
||||
className="shrink-0 grow"
|
||||
style={{ flexBasis: width }}
|
||||
label={label}
|
||||
aria-label={label}
|
||||
/>
|
||||
</ComboboxTrigger>
|
||||
<ComboboxContent
|
||||
|
||||
Reference in new issue
Block a user