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

Restore input checked attribute special case #15

Closed
wants to merge 1 commit into from

Conversation

bqqbarbhg
Copy link
Contributor

@bqqbarbhg bqqbarbhg commented Jul 29, 2023

Turns out the DOM is annoying and removeAttribute("checked") does remove the checked attribute but HTML latches onto user input state if the checkbox is toggled manually.

Demo in the playground:

export default function StickyCheckbox() {
  const state = useState({ checked: true })
  return <>
      <input type="checkbox" checked={state.checked} />
      <button onClick={() => { state.checked = false; }}>Reset</button>
  </>
}
  1. Observe that the reset button works correctly if you don't touch the checkbox
  2. Toggle the checkbox manually off/on
  3. Observe that the reset button does not work anymore

It's possible that it's required for option selected as well.

@bqqbarbhg
Copy link
Contributor Author

Hit a somewhat expected snapshot error, but would have expected the snapshot to at least contain checked instead of checked="true"

  ● kaiku › should toggle attributes for certain boolean attributes

    expect(received).toMatchSnapshot()

    Snapshot name: `kaiku should toggle attributes for certain boolean attributes 4`

    Snapshot: "<div><input type=\"text\" disabled=\"true\"><input type=\"checkbox\" checked=\"true\"><select><option selected=\"true\"></option></select></div>"
    Received: "<div><input type=\"text\" disabled=\"true\"><input type=\"checkbox\"><select><option selected=\"true\"></option></select></div>"

@oamaok
Copy link
Owner

oamaok commented Dec 10, 2023

Fixed in c0db6d1

@oamaok oamaok closed this Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants