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 request - Action option or global handling of 'outside' events #656

Open
lb- opened this issue Feb 11, 2023 · 2 comments · May be fixed by #695
Open

Feature request - Action option or global handling of 'outside' events #656

lb- opened this issue Feb 11, 2023 · 2 comments · May be fixed by #695

Comments

@lb-
Copy link
Contributor

lb- commented Feb 11, 2023

Summary

The action options and global listeners are incredibly powerful. However, it would be great to fill in a common use case gap of an event that triggers only when outside the element is clicked.

Example use cases include focus traps, tooltips that close when something else it focused or clicked on, modals that can close when the user clicks outside the modal, dynamic form behaviour where blur is not suitable.

Proposed usage

<div data-controller="tooltip" data-action="click@outside->tooltip#close focus@outside->tooltip#close" data-tooltip-attached-to-value="#some-id">
  Tooltip content
</div>
<div data-controller="focus-trap" data-action="focus@outside->focus-trap#keep keyup.tab->focus-trap#forward keyup.tab+shift->focus-trap#back">
  An overlay around a modal. 
</div>

Alternative solutions

  1. Don't implement this - instead it could be built as a custom event option, maybe just document it
  2. Implementation via an action filter (like keyboard events) or a built in option (like prevent)

Links

@seb-jean
Copy link
Contributor

It would be great to have an 'outside' event.
It would be useful for dialog and dropdown.

lb- pushed a commit to lb-/stimulus that referenced this issue Jun 20, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the controlled element
- Closes hotwired#656
@lb- lb- linked a pull request Jun 20, 2023 that will close this issue
@lb-
Copy link
Contributor Author

lb- commented Jun 20, 2023

Put this PR together, hope that is ok. #695

lb- pushed a commit to lb-/stimulus that referenced this issue Jun 21, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
lb- added a commit to lb-/stimulus that referenced this issue Jun 21, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
lb- added a commit to lb-/stimulus that referenced this issue Jun 21, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
lb- added a commit to lb-/stimulus that referenced this issue Jun 26, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
lb- added a commit to lb-/stimulus that referenced this issue Aug 20, 2023
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
lb- added a commit to lb-/stimulus that referenced this issue Feb 7, 2024
- When using `@outside`, it will behave the same as @document but only trigger the action if the event was triggered from outside the element with the attached action
- Closes hotwired#656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants