Skip to content

feat(Select): add position prop & align-item#1954

Open
maxffarrell wants to merge 20 commits into
huntabyte:mainfrom
maxffarrell:select-align-item
Open

feat(Select): add position prop & align-item#1954
maxffarrell wants to merge 20 commits into
huntabyte:mainfrom
maxffarrell:select-align-item

Conversation

@maxffarrell

@maxffarrell maxffarrell commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Feb 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4cd0930

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 4cd0930

Comment thread docs/content/components/select.md Outdated
Comment thread packages/bits-ui/src/lib/bits/select/select.svelte.ts Outdated
@huntabyte

Copy link
Copy Markdown
Owner
CleanShot.2026-02-19.at.14.55.28.mp4

This is close, but it needs to account for the scroll buttons potentially being there. I would expect clicking on the trigger and then again quickly without moving my mouse it would hit the selected item and not the scroll button.

I will give this a more thorough review when I have some time, as I see some things in the constructor etc that look like they are causing extra work even when the position is not item-aligned.

Thank you!

@pkg-pr-new

pkg-pr-new Bot commented May 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/bits-ui@1954

commit: 4cd0930

maxffarrell and others added 2 commits May 3, 2026 22:19
Adds documentation, API reference, and demo scaffolding for the upcoming
`position="item-aligned"` feature. Implementation removed — will be
re-ported from Radix UI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Ports the exact SelectItemAlignedPosition algorithm from Radix UI's
select.tsx. Uses a two-div structure (fixed wrapper + content) with
direct DOM style writes, matching Radix's approach:

- Aligns the selected item's center vertically with the trigger's center
- Aligns the item's left edge with the trigger value node's left edge
- Expands the content wrapper as the user scrolls (shouldExpandOnScroll)
- Repositions once when scroll buttons appear (handleScrollButtonChange)
- Closes the select on window resize (Radix behaviour)

Also adds `getAllItemNodes()` to SelectBaseRootState to correctly detect
first/last items (including disabled) for edge padding calculations.
Combobox content types omit `position` since item-aligned doesn't apply
when filtering by typing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d last item

- Replace viewport.offsetTop + itemOffsetMiddle with a getBoundingClientRect-based
  measurement for viewportTopToItemMiddle. When the content element is position:relative
  it becomes the offsetParent and viewport.offsetTop excludes the content's border-top,
  causing a systematic 1-2px downward shift. The rect subtraction cancels the absolute
  position and gives the exact relative offset regardless of CSS position.

- In the expandsUpward=false branch, detect when viewport.scrollTop is clamped (last
  item in a long list can't scroll far enough) and shift the content wrapper upward by
  the uncovered difference so the selected item stays on the trigger center.

- Simplify #repositionOnScroll to a pure BoundingClientRect delta: move the content
  wrapper by (triggerCenterY - itemCenterY) on each page scroll event instead of
  recomputing from the offsetTop/scrollTop formula, keeping it consistent with the
  new measurement strategy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@maxffarrell maxffarrell marked this pull request as ready for review May 4, 2026 03:33
@maxffarrell maxffarrell marked this pull request as draft May 4, 2026 03:34
Remove pageX/pageY (not in PointerEventInit) and fix union type
complexity by casting render args in the item-aligned test helpers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@maxffarrell maxffarrell marked this pull request as ready for review May 4, 2026 04:29
@maxffarrell

Copy link
Copy Markdown
Contributor Author

Working on one last bug, misalignment when last item is selected

…s trailing scroll-down arrow

In item-aligned mode, setHighlightedNode's scrollIntoView call was racing the
positioner and shifting the selected item ~8px from the trigger. Skip that
scroll when item-aligned is active. Additionally, when the last item is at
the trigger position the algorithm leaves a tiny strip of scrollable space
below it; suppress the scroll-down arrow when there is no next item to scroll
to so the menu visually ends at the last item's bottom edge.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@maxffarrell maxffarrell marked this pull request as ready for review May 9, 2026 22:28
…elpers

The dismissable layer attaches its document-level pointerdown listener via
setTimeout(1) to skip the bootstrapping pointerdown event. Tests that open
the menu and immediately click outside can race this delay, leaving the
listener unattached when the click fires. Add a vi.waitFor on
globalThis.bitsDismissableLayers in the open helpers so subsequent outside
clicks reliably hit the dismiss handler.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@maxffarrell maxffarrell marked this pull request as draft May 9, 2026 23:12
@maxffarrell maxffarrell marked this pull request as ready for review May 9, 2026 23:19
@maxffarrell

Copy link
Copy Markdown
Contributor Author

It's working for the most part, but there can be some odd behavior when scrolling page. It lost the anchor once when I scrolled the page up and down fast enough with the menu open, but hard to repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

publish:preview Add to PRs to publish preview packages with `pkg-pr-new`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants