Skip to content

[select] Fix support for transform animations when alignItemWithTrigger is active#3532

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:fix/select-alignitemwithtrigger-transform
Dec 18, 2025
Merged

[select] Fix support for transform animations when alignItemWithTrigger is active#3532
atomiks merged 3 commits into
mui:masterfrom
atomiks:fix/select-alignitemwithtrigger-transform

Conversation

@atomiks

@atomiks atomiks commented Dec 13, 2025

Copy link
Copy Markdown
Contributor

Currently transform animations cause a misalignment with the positioning of alignItemWithTrigger (more noticeable with smaller initial scales or bigger lists). We disable this on our docs, but shadcn/create is using this as a default. Plus Radix seems to handle it correctly.

Exaggerated for effect: https://stackblitz.com/edit/y6zpn7cf

https://deploy-preview-3532--base-ui.netlify.app/react/handbook/animation#animating-select-component-with-motion

@atomiks atomiks added component: select Changes related to the select component. type: bug It doesn't behave as expected. labels Dec 13, 2025
@pkg-pr-new

pkg-pr-new Bot commented Dec 13, 2025

Copy link
Copy Markdown
  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3532
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3532
    

commit: 712ec3e

@mui-bot

mui-bot commented Dec 13, 2025

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+427B(+0.10%) 🔺+140B(+0.11%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Dec 13, 2025

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 712ec3e
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/694488ae1d596b0008d97204
😎 Deploy Preview https://deploy-preview-3532--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks force-pushed the fix/select-alignitemwithtrigger-transform branch from b41e14a to c400b24 Compare December 14, 2025 10:24
Comment on lines +294 to +303
const popupTop = positionerRect.top;
const popupHeight = positionerRect.height;
const textCenterY = textRect.top + textRect.height / 2;

const transformOriginY =
popupHeight > 0 ? ((textCenterY - popupTop) / popupHeight) * 100 : 50;

const clampedY = clamp(transformOriginY, 0, 100);

popupElement.style.setProperty('--transform-origin', `50% ${clampedY}%`);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the addition of try {} finally {} breaks the diff:

This part is new: it maintains a correct transform origin based on the location of the item.

Comment on lines +244 to +248
// Ensure we remove any transforms that can affect the location of the popup
// and therefore the calculations.
const originalTransform = popupElement.style.transform;
popupElement.style.transform = 'none';
popupElement.style.removeProperty('--transform-origin');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The key solution is to remove any transforms when doing the initial calculations (which is the "final" state of the popup location) then restore it back afterwards.

@atomiks atomiks force-pushed the fix/select-alignitemwithtrigger-transform branch from c400b24 to d2eb3af Compare December 14, 2025 10:27
@atomiks atomiks marked this pull request as ready for review December 14, 2025 10:38
@atomiks atomiks force-pushed the fix/select-alignitemwithtrigger-transform branch from 8cb8c74 to d81e200 Compare December 14, 2025 20:30

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks nice. 👍
Fixes the initially (on first open) misplaced Popup problem. 👌

P.S. Best to review by adding ?w=1 to the URL (hide whitespace).

@atomiks

atomiks commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

P.S. Best to review by adding ?w=1 to the URL (hide whitespace).

TIL!

@atomiks atomiks merged commit bd0b97a into mui:master Dec 18, 2025
23 checks passed
@atomiks atomiks deleted the fix/select-alignitemwithtrigger-transform branch December 18, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: select Changes related to the select component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants