HTML Can Do That

173 points by abhin4v


ryan-duve

I'm a fan of HTML over JS when possible, but I developed skepticism for things like this until I've had firsthand success with them.

A few years ago I heard about datalist and thought it was great, so I went to use it and found it was only implemented if you said the input was of type "email". I thought that was strange and looked up why and, if I remember correctly, the HTML spec abstractly described the requirements but gave only one concrete example, which was email addresses, so that's what browsers implemented.

mort

What I hate about all of this is that so much depends on IDs. When I work on parts of a web page, be it using React or manually writing HTML or using some template engine, I want to reason locally. By using a feature where references between nodes happens through IDs (as opposed to through parent/child relationships or sibling relationships), I need to reason globally. IDs are global, so you need to "allocate" a global ID and make sure to not accidentally re-use one you've used before.

Reducing global reasoning and focusing on ways to enable local reasoning is, IMO, one of the primary ways to keep a code base maintainable and comprehensible across years of evolution. It's why types are so effective: you can reason locally as long as you have a type definition available; you don't need to think about the parts of your code base which produces a value in order to work on the parts which consume a value.

In React, you could in principle have an ID allocator in JavaScript to gain back some of that local reasoning, or generate UUIDs for IDs, though I've never seen anyone do that in practice. But when writing HTML or using template engines, that would all have to manually taken care of by the programmer.

Also, am I the only one who thinks it's weird that it's on button to have a popovertarget? If they wanted to let a button control a <details> section, would they add a new detailstarget attribute to button? Wouldn't it make more sense for a button to just have a target to which it sends an activation event, so that it's on the receiver to decide how it acts when activated? This goes back to local reasoning again, just in terms of a standard rather than a program; why does the standard make it so that the section defining the <button> element has to know about the section defining <div ... popover>?