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

Pattern to display a chip conditionally? #1868

Closed
ddahan opened this issue Jun 13, 2024 · 2 comments
Closed

Pattern to display a chip conditionally? #1868

ddahan opened this issue Jun 13, 2024 · 2 comments
Labels
question Further information is requested

Comments

@ddahan
Copy link

ddahan commented Jun 13, 2024

Description

Hi there.
This may be a dumb question, but to use components like UChip, I'm wondering how am I supposed to display it conditionally. Obviously, this does not work because if condition is false, nothing is displayed at all:

<template>
  <UChip v-if="condition">
    <UButton icon="i-heroicons-inbox" color="gray" />
  </UChip>
</template>

My current workaround is something like:

<template>
  <UChip v-if="condition">
    <UButton icon="i-heroicons-inbox" color="gray" />
  </UChip>
  <UButton v-else icon="i-heroicons-inbox" color="gray" />
</template>

But I don't like it as it forces to repeat the content. In the end, I feel forced to extract it in another component, like this:

<template>
  <UChip v-if="condition">
    <MyGreyInboxButton />
  </UChip>
  <MyGreyInboxButton v-else />
</template>

Did I miss something here? Thanks.

@ddahan ddahan added the question Further information is requested label Jun 13, 2024
Copy link
Member

benjamincanac commented Jun 13, 2024

You can use the show prop to display it conditionally: https://ui.nuxt.com/components/chip#show

@ddahan
Copy link
Author

ddahan commented Jun 13, 2024

Thanks a lot, I feel dumb, but relieved :D

@ddahan ddahan closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants