refactor(combobox): streamline logic#14778
Draft
jcfranco wants to merge 4 commits into
Draft
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Combobox component to simplify selection/chip-layout logic and centralize a viewport helper in shared DOM utilities, with the goal of making the component easier to maintain and extend.
Changes:
- Extracted viewport detection into a shared
inViewporthelper inutils/dom.ts. - Moved/streamlined Combobox selection and chip layout computations into reusable helpers and introduced
commitSelection/ref syncing for cleaner internal flows. - Added unit tests for the new Combobox utility helpers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/components/src/utils/dom.ts | Adds shared inViewport helper used by Combobox keyboard navigation. |
| packages/components/src/components/combobox/utils.ts | Introduces exported selection + chip-layout helper functions to streamline Combobox logic. |
| packages/components/src/components/combobox/utils.spec.ts | Adds tests for the new Combobox utility helpers. |
| packages/components/src/components/combobox/combobox.tsx | Refactors internal selection/chip logic to use new utilities, adds batching/commit helpers, and switches to refs/getters for rendered elements. |
Comment on lines
+1
to
+9
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| getCompactSelectionDisplayBreakpoint, | ||
| getFitCompactDisplayState, | ||
| getPlaceholderWidth, | ||
| getSelectedItems, | ||
| orderValuesByPrevious, | ||
| syncAncestorSelection, | ||
| } from "./utils"; |
Comment on lines
+24
to
+34
| export function getSelectedItems( | ||
| items: ComboboxItem["el"][], | ||
| selectionMode: Combobox["selectionMode"], | ||
| ): ComboboxItem["el"][] { | ||
| if (isSingleLike(selectionMode)) { | ||
| const match = items.find(({ selected }) => selected); | ||
| return match ? [match] : []; | ||
| } | ||
|
|
||
| return items.filter((item) => item.selected && (selectionMode !== "ancestors" || !hasActiveChildren(item))); | ||
| } |
Comment on lines
+715
to
+717
| /** | ||
| * Helper to determine if an element is within the viewport. | ||
| */ |
Contributor
|
This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue: #14681
Summary
✨🧹✨