Skip to content

refactor(combobox): streamline logic#14778

Draft
jcfranco wants to merge 4 commits into
devfrom
jcfranco/14681-streamline-combobox
Draft

refactor(combobox): streamline logic#14778
jcfranco wants to merge 4 commits into
devfrom
jcfranco/14681-streamline-combobox

Conversation

@jcfranco

@jcfranco jcfranco commented Jul 8, 2026

Copy link
Copy Markdown
Member

Related Issue: #14681

Summary

✨🧹✨

jcfranco and others added 4 commits July 8, 2026 11:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the refactor Issues tied to code that needs to be significantly reworked. label Jul 8, 2026
@jcfranco
jcfranco requested a review from Copilot July 13, 2026 21:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 inViewport helper in utils/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.
*/
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot added the Stale Issues or pull requests that have not had recent activity. label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Issues tied to code that needs to be significantly reworked. Stale Issues or pull requests that have not had recent activity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants