-
Notifications
You must be signed in to change notification settings - Fork 3
Consider using IDs for target
#2
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
Comments
Just for my own knowledge—how did you find this? Excited you did! Just curious where the traction is coming from. I might add something to the README encouraging people to open issues if they want to comment on the ideas. I think this is a good suggestion! I had not considered it, and might include it as an alternative. Some initial thoughts:
I definitely want to support that design pattern, but also, simple cases should be allowed to be simple! That's one of the nice qualities of HTML. So I don't see why you wouldn't make the whole range of selectors available. |
I confirm also that in many apps using htmx I don't remember using something else than an ID but it's probably just an usage. That said, the example with But there is an inconsistency in the proposal with the current behavior of target in |
Exactly! For simple pages, with only one form, you should be able to just write "target the form."
This is addressed by the proposal. If there is a iframe name that matches the value of the target attribute, that takes precedence. |
I like the idea of having all the selectors available. To answer your earlier question-- Carson linked this repo in an answer he gave on a thread in /r/htmx. |
Carson mentioned it on Reddit https://www.reddit.com/r/htmx/comments/1ehjw7v/minimal_htmx_for_html_proposal/
My concern is that if this project is serious about being adopted as an HTML standard, we've got to use HTML conversions, JavaScript is it's own thing.
Ideally you would already have an ID on your
I'd argue there's a lot of simplicity in only using one way to reference any element on the page. The consistency across all of HTML is simple. |
You're probably right.
Do we know why |
I was going to mention this in another issue so this one doesn’t stay off topic but given the logic above, I think using the |
Actually using |
Then it could be possible to target an element in an iframe ! |
These are all great suggestions. I'm going to include them as alternatives in the proposal itself. I personally still like
Yes, but... there's a reason that
Not all pages need skip-to-content links: sometimes the page is all content, and sometimes the content is small. It's not a convention that every HTML element needs to have an ID.
I don't really buy the idea that only JavaScript should have access to CSS selectors because:
The library ecosystem makes use of CSS selectors because it's the most flexible paradigm: unpoly; htmx |
Maybe there are recent discussions about this choice for popover ? |
I meant "targeting the destination of requests" but I take your point! I'm not saying there's no precedent for "selecting a thing in the DOM based on an ID", that would obviously be silly. I just think it's too limited to really accomplish what I'd like to see this do. |
I agree a query selector has better ergonomics for general use cases, but not for this specific situation. Standards are about paving the cow paths and I can't find the cow path in taking a single HTML fragment returned by the server and spreading it across multiple elements on the page? I think you're trying to optimize for a problem that doesn't exists.
I think it's fine for JavaScript to have access to CSS selectors because it's intended to extend/augment both CSS and HTML. (Jeremy Keith describes this as "the pace layers of the web".) I'm not anti-evolution just anti-unnecessary-complexity. I think supporting the query selector API in this case creates more room for confusion than ergonomic advantages, I think it's a weak reason to break a strong precedent in HTML. Ok, I've got one more framing on this issue, and I'm having trouble finding the right way to express it, so bear with me here...The query selector API is the wrong abstraction for this problem, here's why: I love HTML because it's so powerful, it can represent a ton of behavior and semantics around UI in such a terse, declarative syntax. I think when developers reach for an attribute like
I think using a query selector optimizes for case 1, it's more expressive and allows you easy toss the stuff that came from the server anywhere on the page. But, I'd argue that case 2 is more commonly the intention behind using |
<a href="/home" target="main">Home</a>
<main> <!-- Existing page content --> </main> This proposal appears to change the meaning of Currently I love the idea presented but I wonder if changing the semantics in this way is likely to hinder progress towards getting it accepted as a standard?
I feel like this is confusing and too 'overloaded'. If there's a frame with the same name already does that make the feature unusable? And any existing sites using a named new window target may suddenly find responses unexpectedly loading into an element of the same name instead. Why not define something more compatible with the existing semantics, e.g. either a new separate attribute or some syntax for appending the query selector after the frame name? |
Hey, first off, this is a cool idea I hope it gets some traction. I wanted to leave my two cents here because I've created an Alpine.js plugin (https://alpine-ajax.js.org) with very similar goals.
I'm curious - have you considered limiting
target
to accept only element IDs? I'm not aware of any existing HTML attribute that references elements using a selector string, but there is precedent for using one or more (space separated) Element IDs likeform
,aria-*
, andpopovertarget
. I get that targeting classes can be convenient, but practically I haven't come across a serious need for it. I've found that the explicitness of IDs also guards against unintended DOM updates that could happen when using class selectors in a complex UI.The text was updated successfully, but these errors were encountered: