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

Bug: Checked attribute does not update in the dom #24439

Closed
stefanylaforest opened this issue Apr 25, 2022 · 3 comments
Closed

Bug: Checked attribute does not update in the dom #24439

stefanylaforest opened this issue Apr 25, 2022 · 3 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@stefanylaforest
Copy link

stefanylaforest commented Apr 25, 2022

React version:

Steps To Reproduce

  1. Go to React's code pen example you can find the link in the documentation here
  2. Inspect " is going " checkbox element
  3. uncheck the checkbox

Screen Shot 2022-04-25 at 4 39 52 PM

Link to code example: https://codepen.io/gaearon/pen/wgedvV?editors=0010

The current behavior

dom does not update, the checked attribute stays no matter what.
same goes if the initial state is set to false, the checked attribute never appears on the input element.

The expected behavior

The checked attribute should be removed if not checked.

@stefanylaforest stefanylaforest added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 25, 2022
@gaearon
Copy link
Collaborator

gaearon commented Apr 25, 2022

The current behavior is correct.

The confusion stems from the browser reporting the attribute values. However, React sets the checked property on the DOM node. Setting a property is the correct way to update something — attributes are primarily meant to reflect the initial HTML that was loaded in the browser.

React does update attribute in some cases, notably for inputs value. However, this has led to a large number of problems, and we're actually planning to switch it back to only update the property.

So the behavior for the checked property is better.

@gaearon gaearon closed this as completed Apr 25, 2022
@eps1lon
Copy link
Collaborator

eps1lon commented Apr 25, 2022

For CSS selectors you'd want to use :checked since [checked] wouldn't work for uncontrolled components with plain HTML anyway.

@dkilgore-eightfold
Copy link

Isn't this an Accessibility issue? It's impacting a project I'm working on and am curious if there's a recommended work-around to update this attribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

4 participants