Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(Combobox): fix element height with description #1977

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/form/ComboBox/ComboBoxVirtualizedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ export const ComboBoxVirtualizedList = (props: ComboBoxVirtualizedListProps) =>

const getHeight = () => {
const hasAnyGroupHeader = elements.some((el) => (el.key as string).includes(GROUP_ITEM_KEY))
const hasDescription = elements.some(
(el) => (el.props?.children?.props?.option?.description as string)?.length > 0,
)

const itemheightDelta = hasDescription ? 8 : 4

// recommended perf best practice
if (itemCount > 5) {
return 5 * (ITEM_HEIGHT + 4) + 4 // Add 4px for margins
return 5 * (ITEM_HEIGHT + itemheightDelta) + 4 // Add 4px for margins
} else if (itemCount <= 2 && hasAnyGroupHeader) {
return itemCount * (ITEM_HEIGHT + 2) // Add 2px for margins
} else if (itemCount <= 2 && hasDescription) {
return itemCount * (ITEM_HEIGHT + itemheightDelta) + 4 // Add 4px for margins
}
return itemCount * (ITEM_HEIGHT + 4) + 4 // Add 4px for margins
return itemCount * (ITEM_HEIGHT + itemheightDelta) + 4 // Add 4px for margins
}

// reset the `VariableSizeList` cache if data gets updated
Expand Down
Loading