Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ensure--button-width and--input-width are always up to date#3786

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
RobinMalfait merged 3 commits intomainfromfix/issue-3612
Sep 8, 2025

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where the--button-width and--input-width CSS variables weren't always up to date.

We compute these values initially when the component mounts based on thegetBoundingClientRect of the button and input elements.

To ensure we catch changes in size, we setup aResizeObserver that watches for changes to the button and input elements.

Unfortunately,ResizeObserver doesn't fire when the size changes due to CSS properties such astransform orscale. As far as I can tell, there isn't a single event or Observer we can use to catch all possible changes.

One solution to this problem would be to delay the computation of the sizes until after all transitions have completed and then we could even introduce a small delay to ensure everything is in its final state.

However, you could literally usehover:scale-110 on the Listbox button which would mean that the size changes whenever you hover over the button.

To fix this in a more generic way, we setup arequestAnimationFrame loop that checks the size of the button and input elements on each frame. If the size has changed, we update the CSS variables.

Note: we will only re-render if the size has actually changed, so this shouldn't cause unnecessary re-renders.

The internal hook we use (useElementSize) also now receives anenabled option such that we only run thisrequestAnimationFrame loop when the component is enabled.

For components such as theCombobox,Listbox andMenu that means that we only start measuring when the corresponding dropdown is in an open state.

Hopefully we can fix this kind of issue with an Observer in the future (e.g.:PerformanceObserver withLayoutShift (https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift)) but this is still experimental today.

Fixes:#3612
Fixes:#3598

RyanMcDonald and mohammadhosseinmoradi reacted with heart emoji
Ideally we can listen to some sort of event (via ResizeObserver), but aResizeObserver doesn't see visual changes in width when using the`scale` property.As far as I can tell there doesn't exist any event or observer we canuse to watch for changes in the bounding client rect of an element.This fixes that by introducing a requestAnimationFrame loop. To make itsomewhat efficient, we will make sure to:1. Only run them when the hook is enabled (see previous commit). This   allows us to only run this code when a Listbox or Menu is open for   example.2. As long as the size doesn't change, we won't trigger a re-render.
@vercelVercel
Copy link

vercelbot commentedSep 8, 2025
edited
Loading

The latest updates on your projects. Learn more aboutVercel for GitHub.

ProjectDeploymentPreviewCommentsUpdated (UTC)
headlessui-reactReadyReadyPreviewCommentSep 8, 2025 2:23pm
headlessui-vueReadyReadyPreviewCommentSep 8, 2025 2:23pm

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Listbox button width is incorrect when the parent Popover has a scale transition --button-width incorrect when parent is rendered with an animation

1 participant

@RobinMalfait

[8]ページ先頭

©2009-2025 Movatter.jp