Skip to content

Commit

Permalink
Fix overflow on combobox for hierarchical model (#5442)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalabbad authored Jan 13, 2025
1 parent 22d1e5b commit bc53d5e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog/5431.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed text overflow when there is too many options when selecting a relationship with a hierarchical model
4 changes: 2 additions & 2 deletions frontend/app/src/entities/ipam/ip-namespace-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const IpNamespaceSelectorContent = ({ namespaces }: IpNamespaceSelectorContentPr
{selectedNamespace?.display_label ?? defaultNamespace?.display_label}
</ComboboxTrigger>

<ComboboxContent align="start">
<ComboboxList fitTriggerWidth={false} className="max-w-md">
<ComboboxContent align="start" fitTriggerWidth={false}>
<ComboboxList className="max-w-md">
{namespaces.map((namespace) => (
<ComboboxItem
key={namespace.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,41 @@ describe("RelationshipHierarchicalComboboxList", () => {
expect(onSelect).toHaveBeenCalledOnce();
expect(onSelect).toHaveBeenCalledWith(childRelationships[1]);
});

it("displays load more button when there are more results", async () => {
// GIVEN
const manyRelationships = Array.from({ length: 20 }, (_, i) => ({
id: `test-id-${i}`,
display_label: `Test Relationship ${i}`,
__typename: rootSchema.kind,
}));
vi.mocked(getRelationships).mockResolvedValue(manyRelationships);

// WHEN
const component = render(
<RelationshipHierarchicalComboboxList peer={rootSchema.kind} onSelect={vi.fn()} />
);

// THEN
await expect.element(component.getByRole("option", { name: "Load more" })).toBeVisible();
});

it("shows scrollbar when there are many options", async () => {
// GIVEN
const manyRelationships = Array.from({ length: 30 }, (_, i) => ({
id: `test-id-${i}`,
display_label: `Test Relationship ${i}`,
__typename: rootSchema.kind,
}));
vi.mocked(getRelationships).mockResolvedValue(manyRelationships);

// WHEN
const component = render(
<RelationshipHierarchicalComboboxList peer={rootSchema.kind} onSelect={vi.fn()} />
);

// THEN
const listbox = component.getByRole("listbox");
expect(listbox.element().scrollHeight).toBeGreaterThan(listbox.element().clientHeight);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ export const RelationshipHierarchicalContent = ({
<RelationshipComboboxList {...props} />
</PopoverTabsContent>

<PopoverTabsContent
value="tree"
style={{
maxHeight: "min(var(--radix-popover-content-available-height), 300px)",
width: "var(--radix-popover-trigger-width)",
}}
>
<PopoverTabsContent value="tree">
<RelationshipHierarchicalComboboxList {...props} />
</PopoverTabsContent>
</PopoverTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ export const RelationshipInput = React.forwardRef<
</PopoverTrigger>
</Tooltip>

<ComboboxContent align="end" onOpenAutoFocus={() => loadPoolList()}>
<ComboboxList style={{ width: "auto" }}>
<ComboboxContent
align="end"
fitTriggerWidth={false}
onOpenAutoFocus={() => loadPoolList()}
>
<ComboboxList>
{!isPoolListLoading && <ComboboxEmpty>No pools found</ComboboxEmpty>}

{!isPoolListLoading &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export default function BreadcrumbBranchSelector({
{value}
</ComboboxTrigger>

<ComboboxContent align="start">
<ComboboxList fitTriggerWidth={false}>
<ComboboxContent align="start" fitTriggerWidth={false}>
<ComboboxList>
<CommandEmpty>No branch found.</CommandEmpty>
{branches.map((branch) => {
const branchUrl = constructPath(`/branches/${branch.name}`);
Expand Down
31 changes: 16 additions & 15 deletions frontend/app/src/shared/components/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,33 @@ export const ComboboxTrigger = React.forwardRef<HTMLButtonElement, ComboboxTrigg

export const ComboboxContent = React.forwardRef<
React.ElementRef<typeof PopoverContent>,
React.ComponentPropsWithoutRef<typeof PopoverContent>
>(({ className, ...props }, ref) => {
React.ComponentPropsWithoutRef<typeof PopoverContent> & { fitTriggerWidth?: boolean }
>(({ className, fitTriggerWidth = true, style, ...props }, ref) => {
return (
<PopoverContent ref={ref} className={classNames("p-0", className)} portal={false} {...props} />
<PopoverContent
ref={ref}
className={classNames("p-0", className)}
portal={false}
style={{
...(fitTriggerWidth
? { width: "var(--radix-popover-trigger-width)" }
: { minWidth: "var(--radix-popover-trigger-width)" }),
...style,
}}
{...props}
/>
);
});

export const ComboboxList = React.forwardRef<
React.ElementRef<typeof CommandList>,
React.ComponentPropsWithoutRef<typeof CommandList> & {
fitTriggerWidth?: boolean;
shouldFilter?: boolean;
onValueChange?: (search: string) => void;
}
>(({ fitTriggerWidth = true, style, shouldFilter, autoFocus, onValueChange, ...props }, ref) => {
>(({ shouldFilter, autoFocus, onValueChange, ...props }, ref) => {
return (
<Command
style={{
maxHeight: "min(var(--radix-popover-content-available-height), 300px)",
...(fitTriggerWidth
? { width: "var(--radix-popover-trigger-width)" }
: { minWidth: "var(--radix-popover-trigger-width)" }),
...style,
}}
shouldFilter={shouldFilter}
>
<Command shouldFilter={shouldFilter}>
<CommandInput placeholder="Filter..." autoFocus={autoFocus} onValueChange={onValueChange} />
<CommandList ref={ref} {...props} />
</Command>
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/src/shared/components/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const CommandList = React.forwardRef<
>(({ className, ...props }, ref) => (
<CommandPrimitive.List
ref={ref}
className={classNames("flex-grow p-2 rounded-md overflow-y-auto overflow-x-hidden", className)}
className={classNames(
"max-h-[300px] flex-grow p-2 rounded-md overflow-y-auto overflow-x-hidden",
className
)}
asChild
{...props}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/shared/components/ui/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const Pagination = (props: tPaginationType) => {
<Combobox>
<ComboboxTrigger data-testid="pagination-size-select">{limit}</ComboboxTrigger>

<ComboboxContent>
<ComboboxContent fitTriggerWidth={false}>
<Command>
<CommandList>
{[10, 20, 50].map((option) => {
Expand Down

0 comments on commit bc53d5e

Please sign in to comment.