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

List extended selectors + caveats in hx-include doc #1522

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

Telroshan
Copy link
Collaborator

This addresses issue #1509

  • hx-include supports the extended selectors, which were not mentioned in its documentation
  • The behaviour of find for example, can be confusing when using an inherited hx-include attribute: added a note to explain that
  • Extended selectors only return a single element, which could be confusing compared to a standard CSS selector that returns all elements matching that selector: added a note to explain that

@Telroshan Telroshan changed the title List extended selectors + caveats in hx-include doc [Documentation] List extended selectors + caveats in hx-include doc Jun 27, 2023
Copy link
Contributor

@checketts checketts left a comment

Choose a reason for hiding this comment

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

Good clarifications!

@alexpetros alexpetros added documentation Improvements or additions to documentation under discussion Issues that are being considered but require further alignment labels Jul 17, 2023
@alexpetros
Copy link
Collaborator

I wonder if copy-pasting that bit about the find, closest, etc. mini-language everywhere is the way to go, or if we shouldn't standardize it somehow.

@Telroshan
Copy link
Collaborator Author

That's the next thing I was going to suggest! 😄
Since they are used for hx-include, hx-indicator, hx-target, hx-trigger's from modifier, and probably others that I'm forgetting, I think we should give the htmx's extended selectors syntax its own page and link to that page in every attribute doc supporting the syntax.
I'm afraid we would inevitably have differences and outdated descriptions in each attribute's doc otherwise

@alexpetros
Copy link
Collaborator

My only concern is that I think the trigger syntax and the other ones are parsed separately, which doesn't necessarily mean they should be separate in the documentation, but it's possible they could diverge

@Telroshan
Copy link
Collaborator Author

I hadn't noticed this, indeed others use querySelectorAllExt while getTriggerSpecs does its own parsing.
Though, looking at the code, getTriggerSpecs's logic is just "is the keyword one of the following predefined extended selectors ? If so, parse one more token", but then this parsed selector is also resolved through querySelectorAllExt

  • I can't think of any reason hx-trigger's from would need to use a different selectors set than, say, hx-include
  • if you're concerned about the duplication here @alexpetros (technically, the extended selectors are hardcoded at 2 places in the code), maybe we could do an array, a map or something else there, to factor the logic and define the selectors only once?
    Probably a dumb idea but what comes to the top of my head is an { "selectorName": function }, such as
var extendedSelectors = {
    "closest": (elt, selector) => [closest(elt, normalizeSelector(selector.substr(8)))],
    "find": (elt, selector) => [find(elt, normalizeSelector(selector.substr(5)))],
    ...
}

(Using the short syntax on purpose here but ofc this isn't IE11 compatible)
Basically querySelectorAllExt's code, but as a map instead of a if-else series, thus something that can be iterated from another place in the code, to loop through all defined extended selectors without hardcoding them once again

@alexpetros
Copy link
Collaborator

alexpetros commented Nov 6, 2023

I wonder if copy-pasting that bit about the find, closest, etc. mini-language everywhere is the way to go, or if we shouldn't standardize it somehow.

After letting this sit for too long, I've decided that just because we should do this eventually isn't a reason to hold up this PR. This is at least a step in the right direction.

@alexpetros alexpetros changed the title [Documentation] List extended selectors + caveats in hx-include doc List extended selectors + caveats in hx-include doc Nov 6, 2023
@alexpetros alexpetros merged commit 563ce5d into bigskysoftware:dev Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation under discussion Issues that are being considered but require further alignment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants