Skip to content

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

Merged
SteffenDE merged 1 commit intomainfrom
gr-scope-docs
Jan 26, 2025
Merged

Document how to use scopes in JS commands for DOM selectors#3638
SteffenDE merged 1 commit intomainfrom
gr-scope-docs

Conversation

@Gazler
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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