Skip to content

[docs] Tabs examples with motion #1613

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Mar 28, 2025

#1494
#1486

Demo: https://deploy-preview-1613--base-ui.netlify.app/experiments/tabs/motion

  • Used mode="wait" on AnimatePresence, the entering child waits until the exiting child has animated out, other modes should be possible, though extra display/positioning styles would be required (set via motion) to prevent overlap:
    Screenshot 2025-03-29 at 1 41 42 AM (3)
  • If using Tailwind v4, setting hidden={undefined} on Tabs.Panel is required to ensure the panel is visible during the exit animation (same workaround as Collapsible)
  • Replicating the indicator transition from the docs styles with motion turns out to be tricker than the panel, it can't seem to transition the same CSS variable that changes value:
// doesn't work even with the entries repeated in `initial`/`exit`
<Tabs.Indicator render={
  <motion.div
    animate={{
      translate: 'var(--active-tab-left) -50%',
      width: 'var(--active-tab-width)',
    }}
  />
}

@mj12albert mj12albert added the component: tabs This is the name of the generic UI component, not the React module! label Mar 28, 2025
Copy link

netlify bot commented Mar 28, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 6692c29
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67ebb9e814ff670008af9c57
😎 Deploy Preview https://deploy-preview-1613--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 site configuration.

keepMounted
hidden={undefined}
{...otherProps}
render={(renderProps, state) => {
Copy link
Member Author

@mj12albert mj12albert Mar 28, 2025

Choose a reason for hiding this comment

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

It would be handy for the state here to provide all the --active-tab-* values to plug into motion

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it doesn't matter, it accepts CSS variables anyway

https://motion.dev/docs/react-animation#css-variables

Copy link
Member Author

Choose a reason for hiding this comment

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

Couldn't get motion to animate based on these value, raw values are actually already in state.selectedTabSize/Position.*

Maybe motion values have to be used: https://motion.dev/docs/react-motion-value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant