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

Document how to use scopes in JS commands for DOM selectors #3638

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

Gazler
Copy link
Member

@Gazler Gazler commented Jan 17, 2025

No description provided.

* `{:closest, "selector"}` To target the closest element within the interacted
element.

For example, if building a dropdown component, the button could use the `:inner`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that with this example, if there was any kind of nested dropdown, the nested ones would be targeted as well. For a dropdown probably not that relevant, but when doing dialogs it could be problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, the same rule applies when passing a string as a selector, so perhaps closest is the outlier here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe it would make sense to mention this. The default and inner variant target multiple elements (-> document/element.querySelectorAll) and closest stops when it finds the first match (-> element.closest). As this is "Phoenix.LiveView.JS", we could even link to the docs for those?

@SteffenDE SteffenDE merged commit 552c3fe into main Jan 26, 2025
16 checks passed
@SteffenDE SteffenDE deleted the gr-scope-docs branch January 26, 2025 15:13
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

Successfully merging this pull request may close these issues.

2 participants