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

Open a modal inside a dropdown #177

Closed
elalemanyo opened this issue Jan 10, 2023 · 10 comments
Closed

Open a modal inside a dropdown #177

elalemanyo opened this issue Jan 10, 2023 · 10 comments

Comments

@elalemanyo
Copy link

elalemanyo commented Jan 10, 2023

Hi,
Is there a way to open a modal inside a dropdown?
Thanks!

@elalemanyo elalemanyo changed the title Open a modal from a dropdown Open a modal inside a dropdown Jan 10, 2023
@acejam
Copy link

acejam commented Sep 13, 2023

@elalemanyo Did you ever find a solution to this? I came across the same issue.

@excid3
Copy link
Owner

excid3 commented Sep 14, 2023

What are you having trouble with?

@acejam
Copy link

acejam commented Sep 14, 2023

What are you having trouble with?

@excid3 The issue is the modal does not open. I have a basic dropdown menu. One of the menu items is a link, which should open a modal when clicked.

My code is very similar to the provided usage examples. From a code structure perspective, I effectively have modal example code inside of dropdown example code. Here is a gist that shows my exact issue:

https://gist.github.com/acejam/6a678e54739651b8d32e4c3e1ea6a44f

The browser console will through a Uncaught (in promise) DOMException: The user aborted a request.

Is there a better way to launch a modal from a dropdown menu?

@excid3
Copy link
Owner

excid3 commented Sep 14, 2023

You might need to use the :prevent Stimulus option on the modal link's click action.

@acejam
Copy link

acejam commented Sep 14, 2023

You might need to use the :prevent Stimulus option on the modal link's click action.

That's actually one of the first things that I tried. Unfortunately, it did not make any difference.

@excid3
Copy link
Owner

excid3 commented Sep 14, 2023

Can you update your example with what you tried?

@acejam
Copy link

acejam commented Sep 14, 2023

Can you update your example with what you tried?

Sure, it was very basic though: data-action="click->modal#open:prevent"

My thinking is that the Dropdown and Modal controllers are stepping on each other here. Perhaps because we have one data-controller inside of another data-controller?

@acejam
Copy link

acejam commented Sep 19, 2023

@excid3 Unfortunately I'm still battling against this. I was able to get rid of the The user aborted a request error by commenting out the promise code from transition.js. I think the two Stimulus controllers are stepping on each other somehow.

@excid3
Copy link
Owner

excid3 commented Sep 20, 2023

I fiddled with it, but didn't have enough time to figure out what was going wrong. Also, the modal being inside a relative element made the modal show up inside the menu, so that CSS needs some adjustment too.

@excid3
Copy link
Owner

excid3 commented Mar 22, 2024

This should work now that we're using the <dialog> element for modals and slideovers.

@excid3 excid3 closed this as completed Mar 22, 2024
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

3 participants