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

Unable to animate Button with Transition component #3037

Open
fech-dev opened this issue Jan 7, 2025 · 4 comments · May be fixed by #3066
Open

Unable to animate Button with Transition component #3037

fech-dev opened this issue Jan 7, 2025 · 4 comments · May be fixed by #3066
Labels
bug Something isn't working triage v3 #1289

Comments

@fech-dev
Copy link

fech-dev commented Jan 7, 2025

Environment

  • Operating System: Linux
  • Node Version: v22.12.0
  • Nuxt Version: 3.15.1
  • CLI Version: 3.18.2
  • Nitro Version: 2.10.4
  • Package Manager: pnpm@9.15.0
  • Builder: -
  • User Config: devtools, modules, css, future, compatibilityDate, eslint
  • Runtime Modules: @nuxt/ui@3.0.0-alpha.9, @nuxt/eslint@0.7.4, @vueuse/nuxt@12.3.0
  • Build Modules: -

Is this bug related to Nuxt or Vue?

Nuxt

Version

3.0.0-alpha.x

Reproduction

nuxt-ui-button-transition-repro

Description

I'm unable to animate (or use transitions) with vue's Transition component with UButton. I've noticed that the UButton uses NuxtLink that renders a fragment. This is causing the problem, since Transition component will not be able to work with fragments.

Additional context

No response

Logs

[Vue warn]: Component inside <Transition> renders non-element root node that cannot be animated. 
  at <NuxtLink class="rounded-[calc(var(--ui-radius)*1.5)] font-medium inline-flex items-center focus:outline-none disabled:cursor-not-allowed aria-disabled:cursor-not-allowed disabled:opacity-75 aria-disabled:opacity-75 transition-colors px-2.5 py-1.5 text-sm gap-1.5 text-[var(--ui-bg)] bg-[var(--ui-primary)] hover:bg-[var(--ui-primary)]/75 disabled:bg-[var(--ui-primary)] aria-disabled:bg-[var(--ui-primary)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ui-primary)]" raw=true custom="" > 
  at <ULink type=undefined disabled=false class="rounded-[calc(var(--ui-radius)*1.5)] font-medium inline-flex items-center focus:outline-none disabled:cursor-not-allowed aria-disabled:cursor-not-allowed disabled:opacity-75 aria-disabled:opacity-75 transition-colors px-2.5 py-1.5 text-sm gap-1.5 text-[var(--ui-bg)] bg-[var(--ui-primary)] hover:bg-[var(--ui-primary)]/75 disabled:bg-[var(--ui-primary)] aria-disabled:bg-[var(--ui-primary)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ui-primary)]"  ... > 
  at <UButton key="_default1" label="Open" onClick=fn > 
  at <BaseTransition appear=false persisted=false mode=undefined  ... > 
  at <Transition enter-from-class="opacity-0 translate-x-100" enter-active-class="transition duration-400" leave-active-class="transition duration-400"  ... > 
  at <FadeTransition > 
  at <Primitive as=undefined class="max-w-[var(--ui-container)] mx-auto px-4 sm:px-6 lg:px-8 flex flex-col justify-center items-center min-h-screen gap-4" > 
  at <UContainer class="flex flex-col justify-center items-center min-h-screen gap-4" > 
  at <App key=4 > 
  at <NuxtRoot>
@fech-dev fech-dev added bug Something isn't working triage v3 #1289 labels Jan 7, 2025
@HugoRCD
Copy link
Collaborator

HugoRCD commented Jan 7, 2025

@fech-dev Why not wrap the UButton in a div with a key in your case?

<FadeTransition>
  <div :key="isFixUiBtnOpen">
    <UButton
      v-if="isUiBtnOpen"
      label="Close"
      @click="toggleUiBtn(false)"
    />
    <UButton
      v-else
      label="Open"
      @click="toggleUiBtn(true)"
    />
  </div>
</FadeTransition>

@fech-dev
Copy link
Author

fech-dev commented Jan 8, 2025

@HugoRCD Thank you for your answer!

I think adding the div might work as a quick workaround, but it could introduce issues by altering the HTML structure,
which may affect how the CSS styles apply and how the transitions work. Furthermore, it's not an intuitive solution.

Maybe these days I can investigate on this and try to submit a solution.

@fech-dev fech-dev linked a pull request Jan 10, 2025 that will close this issue
8 tasks
@benjamincanac
Copy link
Member

@lihbr @TheAlexLichter Would you have an idea about this? We can't use v-show as well, it produces this warning:

[Vue warn]: Runtime directive used on component with non-element root node. The directives will not function as intended. 
  at <NuxtLink custom="" > 
  at <ULink raw="" > 
  at <Link onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< null > > 

Here is the Link component: https://github.com/nuxt/ui/blob/v3/src/runtime/components/Link.vue#L175

@lihbr
Copy link
Member

lihbr commented Jan 13, 2025

Minimal reproduction in case it helps:

<script lang="ts" setup>
const open = ref(false)
</script>

<template>
  <div>
    <Transition>
      <NuxtLink v-if="open" custom>
        <div @click="open = !open">true</div>
      </NuxtLink>
      <NuxtLink v-else custom>
        <div @click="open = !open">false</div>
      </NuxtLink>
    </Transition>
  </div>
</template>

But I think it's not really something we can fix on <NuxtLink> so easily, (<RouterLink> has the same limitation)

The div-wrapper sounds to me like the best workaround I'm aware of too :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage v3 #1289
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants