Skip to content
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

How does it work with Motion? #1494

Open
subproject22 opened this issue Mar 1, 2025 · 4 comments
Open

How does it work with Motion? #1494

subproject22 opened this issue Mar 1, 2025 · 4 comments
Labels
component: tabs This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@subproject22
Copy link

So I tried to use it similar way as Radix, but it's doesn't work

"use client"

import * as React from "react"
import { useState } from "react"

import { Tabs } from "@base-ui-components/react/tabs"
import { AnimatePresence, motion } from "motion/react"

export function NewTabsDemo() {
  const [active, setActive] = useState("one")
  return (
    <Tabs.Root value={active} onValueChange={setActive} defaultValue="one">
      <Tabs.List>
        <Tabs.Tab value="one">One</Tabs.Tab>
        <Tabs.Tab value="two">Two</Tabs.Tab>
        <Tabs.Tab value="three">Three</Tabs.Tab>
      </Tabs.List>

      <AnimatePresence mode="popLayout">
        {active === "one" && (
          <Tabs.Panel
            className="bg-red-500 p-12"
            value="one"
            keepMounted
            render={
              <motion.div
                initial={{
                  opacity: 0,
                  y: -100,
                }}
                animate={{
                  opacity: 1,
                  y: 0,
                }}
                exit={{
                  opacity: 0,
                  y: 100,
                }}
              />
            }
          >
            one
          </Tabs.Panel>
        )}

        {active === "two" && (
          <Tabs.Panel
            keepMounted
            className="bg-green-500 p-12"
            value="two"
            render={
              <motion.div
                initial={{
                  opacity: 0,
                  y: -100,
                }}
                animate={{
                  opacity: 1,
                  y: 0,
                }}
                exit={{
                  opacity: 0,
                  y: 100,
                }}
              />
            }
          >
            two
          </Tabs.Panel>
        )}

        {active === "three" && (
          <Tabs.Panel
            keepMounted
            className="bg-yellow-500 p-12"
            value="three"
            render={
              <motion.div
                initial={{
                  opacity: 0,
                  y: -100,
                }}
                animate={{
                  opacity: 1,
                  y: 0,
                }}
                exit={{
                  opacity: 0,
                  y: 100,
                }}
              />
            }
          >
            three
          </Tabs.Panel>
        )}
      </AnimatePresence>
    </Tabs.Root>
  )
}

I haven't found a single examples of usage with Motion.

@subproject22 subproject22 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 1, 2025
@atomiks
Copy link
Contributor

atomiks commented Mar 1, 2025

Hi @subproject22, in our next release the docs will be updated with some Motion examples but this mainly pertains to popup-related components, not ones like Tabs.

You can read the updated docs here - we can investigate Motion animations with Tabs soon though

@atomiks atomiks added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 1, 2025
@subproject22
Copy link
Author

hey @atomiks thanks for response. As for my example with Tabs, adding key helps, but still can't make exit animation work.

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

Related to #1486

@mj12albert
Copy link
Member

@subproject22 Just wondering if you've gotten Radix Tabs working well with motion, and if so are you able to share a sandbox or demo 🙏

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! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

4 participants