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

[Feature]: use the same Dialog across component #1573

Closed
2 tasks
enjidev opened this issue Jan 22, 2025 · 4 comments
Closed
2 tasks

[Feature]: use the same Dialog across component #1573

enjidev opened this issue Jan 22, 2025 · 4 comments

Comments

@enjidev
Copy link

enjidev commented Jan 22, 2025

Describe the feature

I checked the docs about abstracting the Dialog component:

<Dialog>
   <DialogTrigger>Dialog trigger</DialogTrigger>
   <DialogContent>Dialog Content</DialogContent>
</Dialog>

But it’s not clear how to use the same Dialog across components.

I’m confused about why DialogTrigger needs to be inside DialogRoot.

In other libraries, like HeadlessUI and NuxtUI, you don’t have to define the trigger inside a root component. This makes it easier to toggle the dialog’s state — for example, with Pinia, I could just toggle the same modal by clicking a button in any components.

Could you share the best way to do this in Reka UI?


I just migrated from Headless UI and recently fell in love with Reka UI. Great work! Thanks!

Additional information

  • I intend to submit a PR for this feature.
  • I have already implemented and/or tested this feature.
@cannap
Copy link

cannap commented Jan 22, 2025

you can use

Image on the DialogRoot to controll the state

@enjidev
Copy link
Author

enjidev commented Jan 22, 2025

i knew it, but when i tried to place the DialogTrigger outside the DialogRoot, it didn’t render and returned the following warning:

hook.js:608 [Vue warn]: Component is missing template or render function: {__name: 'DialogTrigger', props: {…}, setup: ƒ}

moving the DialogRoot to the top-level component, like app.vue in Nuxt, worked. is there a better way to handle this?

@enjidev
Copy link
Author

enjidev commented Jan 22, 2025

in app.vue something like this:

  <DialogRoot>
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </DialogRoot>

but just realized it might not work if i've multiple modals.


to make it clear, let's say i've these modals:

<ModalA />
<ModalB />

and i want to trigger them across components:

Header.vue -> has buttons to toggle ModalA and ModalB
Footer.vue -> same as above, has buttons to toggle the ModalA and ModalB

is the only one way is to reimport the ModalA and ModalB in each Header and Footer component?

@enjidev
Copy link
Author

enjidev commented Jan 25, 2025

i got it working after reading about controlled dialog in Ark UI's docs. hmm 👀

so, i just stopped using the DialogTrigger and used a plain button instead.

@enjidev enjidev closed this as completed Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants