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

Allow multiple triggers to modify a single toggle-able node #105

Open
aaronstezycki opened this issue Mar 30, 2021 · 5 comments
Open

Allow multiple triggers to modify a single toggle-able node #105

aaronstezycki opened this issue Mar 30, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@aaronstezycki
Copy link

aaronstezycki commented Mar 30, 2021

Is your feature request related to a problem? Please describe.
Allowing multiple triggers to interact with the same toggle-able element would be very welcome. For example, a main navigation trigger/button might toggle a modal or 'sidebar' into view. Being able to click on a body link/button trigger to open the same 'sidebar' would allow users the flexibility of which trigger to use to access the modal.

Describe the solution you'd like
Something like ...

<header>
    <button data-toggle-class data-toggle-target=".modal">Open Modal</button>
</header>

<main>
<p><button data-toggle-class data-toggle-target=".modal">This also triggers</button> the modal, but if the modal is already active, it would close the modal instead.</p>
</main>

<!-- is-active from any trigger that targets it -->
<nav class="modal"></nav>

Note: This would also need to work with radio group based triggers. (This is the specific use case I need)

I don't have the time to put together a reduced test case at the minute, but would like to when I have time. This is a great library, and I'd love to see it improve further to solve more edge cases.

@Twikito
Copy link
Owner

Twikito commented Mar 30, 2021

Hi @aaronstezycki 👋
Once again, thanks for taking time to send this request.

I see your problem, here. Since the behaviour is to toggle classes, if you have two different triggers that target the same element, toggling the same classname, you'll have a conflict. I would probably think about a way to link triggers.

In your example, I tried to fix the problem, and it seems you can have a acceptable behaviour by adding data-toggle-outside on each trigger. What do you think?

@Twikito Twikito added the enhancement New feature or request label Mar 30, 2021
@aaronstezycki
Copy link
Author

aaronstezycki commented Mar 31, 2021

With both triggers, or any trigger for that matter, you could have a query function which checks whether the target has the class on it already... then if it has the class already remove the class (or classes) or if it doesn't have the class, add the class on to target. I'm willing to bet this would solve a few different problems that the library might suffer from?

I'll check to see if your solution works in the meantime, altho maybe creating a different data attribute name to solve this use case might be preferable.

@Twikito
Copy link
Owner

Twikito commented Mar 31, 2021

Well, I have already think about such a behaviour, but it can't work since the developer can add whatever classes he wants by default, so on toggling, a trigger or a target can have some and don't have others. The behaviour is to toggle, and not arbitrary choice what to do with the classes that can be already set.

So I think that yes, I may add a new attribute to create a link between triggers.

@henrijs
Copy link

henrijs commented Jul 1, 2021

I agree @Twikito, an attribute would be in order, since there is more going on besides classes, we need to swap ARIA attributes as well properly. My use-case are tabs that become accordion on narrow screens. But I have options, like https://css-tricks.com/transformer-tabs/

@aaronstezycki
Copy link
Author

In your example, I tried to fix the problem, and it seems you can have an acceptable behaviour by adding data-toggle-outside on each trigger. What do you think?

I've just tried this approach and un-fortunately it has some unwanted side effects. :(
Obviously just clicking anywhere on the document might close or toggle the target, which isn't really what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants