w3ctag / design-principles

A small-but-growing set of design principles collected by the TAG while reviewing specifications
https://w3ctag.github.io/design-principles
160 stars 44 forks source link

Guidance about which state properties should be reflected as HTML attributes #289

Open LeaVerou opened 3 years ago

LeaVerou commented 3 years ago

This came up while reviewing <popup> in https://github.com/w3ctag/design-reviews/issues/599#issuecomment-781386845, and more specifically about whether it should have an open attribute like <dialog> and <details>.

There is another issue about keeping IDL attributes and HTML attributes in sync when both exist, but we don't have anything about which IDL attributes should also exist as attributes.

My personal opinion is to err on the side of including attributes for main properties. Providing declarative HTML-based ways to interact with UI controls has several benefits. Off the top of my head:

On the other hand, there have been some arguments against this, I believe primarily centered around performance. In the case of <dialog open>, things got messy I believe due to some inconsistency with the open and close events, I'm not sure if there's anything more general to learn from that.

Anyhow, I think this is something we should discuss, resolve on so that we're all on the same page, and provide guidance about in the form of a design principle.

annevk commented 3 years ago

I think there is an unresolved issue around dialog elements when the events fire. I think if they fire using custom-element-reaction time™ and only in documents with a browsing context it ought to be fine, but that's not the case right now.

The dialog element is also somewhat precedent breaking in that for other form controls, user input never modified the tree. And it's also not clear how to do certain features with that model. E.g., for <textarea> its contents represent the default value. How would you serialize user input?

LeaVerou commented 3 years ago

The dialog element is also somewhat precedent breaking in that for other form controls, user input never modified the tree. And it's also not clear how to do certain features with that model. E.g., for <textarea> its contents represent the default value. How would you serialize user input?

I think that's more a comment for #279, though is is certainly related with this. User input already has a defined serialization for textarea.value. I don't see how this is different, but maybe I'm missing something? There is also precedent for text editing that modifies the tree, with contentEditable. Furthermore, just like the other form elements, the fact that textarea.textContent doesn't actually represent the current value but the default value is incredibly confusing to developers, and I have seen many of them stumble over it badly. So, if <textarea> were to be designed today, I would strongly argue against this pattern.

LeaVerou commented 2 years ago

We discussed this again in today's breakout. We all agree that we don't want any of these two extremes:

It seems that the optimum choices for the Web Platform are somewhere in the middle, but we are having some trouble to zero in on the exact distinction. @plinss came up with a thought experiment, inspired by my point about SSR: If browsers were read-write, what state would you expect to be copied if you copied a part of a webpage? It seems there are aspects of state that are part of the document (i.e. makes more sense to expose) and aspects of state that are external (e.g. hover, focus, :target etc).

Link to minutes

LeaVerou commented 1 year ago

Resolved in today's breakout: @LeaVerou to write a draft principle based on the first comment so we can have something concrete to debate.