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

Improve description of readonly attribute #9496

Open
aaronadamsCA opened this issue Jul 6, 2023 · 6 comments
Open

Improve description of readonly attribute #9496

aaronadamsCA opened this issue Jul 6, 2023 · 6 comments
Labels
clarification Standard could be clearer topic: forms

Comments

@aaronadamsCA
Copy link

The description of the readonly attribute (or the definition of mutability) is currently inaccurate.

The spec clearly states that the readonly attribute makes a form control immutable:

https://html.spec.whatwg.org/#the-readonly-attribute

The readonly attribute is a boolean attribute that controls whether or not the user can edit the form control. When specified, the element is not mutable.

And that mutability is whether or not the user can modify value or checkedness:

https://html.spec.whatwg.org/#mutability

This determines (by means of definitions and requirements in this specification that rely on whether an element is so designated) whether or not the user can modify the value or checkedness of a form control, or whether or not a control can be automatically prefilled.

But when a radio button or checkbox control is readonly, the user can still modify checkedness. So I think one of these definitions needs to be updated.

I also think this note could be made clearer:

Only text controls can be made read-only, since for other controls (such as checkboxes and buttons) there is no useful distinction between being read-only and being disabled, so the readonly attribute does not apply.

I think it would be better to state that the readonly attribute is only useful on text controls because it does not prevents the user from modifying checkedness of a radio button or checkbox control, which means a user can still change its submitted value by changing its checkedness. The note as currently written never quite makes it to this point of clarity.

@annevk
Copy link
Member

annevk commented Jul 6, 2023

I agree that this is somewhat confusing, but I think the current text is still accurate. readonly doesn't apply to checkboxes so that doesn't make them immutable. But something else can make them immutable (disabled).

@annevk annevk added clarification Standard could be clearer topic: forms labels Jul 6, 2023
@aaronadamsCA
Copy link
Author

aaronadamsCA commented Jul 6, 2023

Thanks. You definitely hit the nail on the head as to why I was confused by this:

  1. disabled makes a text box immutable and doesn't submit its value with the form: ✅
  2. disabled makes a checkbox immutable and doesn't submit its value with the form: ✅
  3. readonly makes a text box immutable and submits its value with the form: ✅
  4. readonly makes a checkbox immutable and submits its value with the form: ❌

I don't know if the docs are getting that across right now.

I still think this line may be incorrect, because it seems to mistake cause for effect:

Only text controls can be made read-only, since for other controls (such as checkboxes and buttons) there is no useful distinction between being read-only and being disabled, so the readonly attribute does not apply.

I don't think it's true that readonly does not apply because there's no useful distinction; immutability of checkedness would have been a very useful distinction! Of course that's not actually how it works. I think this shorter version might be less confusing:

Only text controls can be made read-only, since for other controls (such as checkboxes and buttons) the readonly attribute does not apply.

@aaronadamsCA aaronadamsCA changed the title Correct description of readonly attribute (or mutability) Improve description of readonly attribute Jul 13, 2023
@B3rry
Copy link

B3rry commented Sep 15, 2023

I agree that this is somewhat confusing, but I think the current text is still accurate. readonly doesn't apply to checkboxes so that doesn't make them immutable. But something else can make them immutable (disabled).

I don't think this is accurate. read-only as a pseudo class, targets all checkboxes. Based on this, the html readonly attribute may not apply, but the read-only pseudo still styles all checkboxes as if they did have the readonly attribute. The checkboxes may not be immutable, but they are targeted for styling as if they are.

See mdn/content#29140 for an example.

@annevk
Copy link
Member

annevk commented Sep 18, 2023

The pseudo-class matches all elements that do not match :read-write: https://html.spec.whatwg.org/#selector-read-only. And so yes, that includes elements to which the readonly attribute does not apply. That seems orthogonal to this issue.

@B3rry
Copy link

B3rry commented Sep 18, 2023

The pseudo-class matches all elements that do not match :read-write: https://html.spec.whatwg.org/#selector-read-only. And so yes, that includes elements to which the readonly attribute does not apply. That seems orthogonal to this issue.

"The pseudo-class matches all elements that do not match :read-write."

Yes, that is my point, read-only is not an accurate descriptor. Because it is, in functional practice, "not read-write." I think the text should be changed.

@annevk
Copy link
Member

annevk commented Sep 18, 2023

I'm not sure what you are suggesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: forms
Development

No branches or pull requests

3 participants