The closest related issue I could, is somewhat of the inverse of this one: #7711
React version: 16.12 (older versions as well)
<fieldset> with: a <legend> containing an <input> (checkbox) element, and another form element (<select>, <input>, <textarea>).disabled attribute that follows the aforementioned state to the <fieldset>.onChange event of the <input> in the <fieldset> responsible for modifying the state of the component (enabled/disabled). <fieldset> using the <input> in its <legend>.<fieldset>.Link to code example: Sandbox
import React from "react";
export default function App() {
const [enabled, setEnabled] = React.useState(true);
return <React.Fragment>
<fieldset disabled={!enabled}>
<legend>
<input
type="checkbox"
checked={enabled}
onChange={(evt)=>{setEnabled(evt.target.checked);}}/>
</legend>
<textarea></textarea>
</fieldset>
<p>
Disable the above fieldset by unchecking the checkbox. Checking the box once again does not re-enable the fieldset however.
</p>
</React.Fragment>;
}
Enabling the <fieldset> using the <input> in its <legend> changes the state of the <input> in unchecked fashion; it does not fire its onChange event and its value does thus no longer match the state of the component.
Based on the W3C and WHATWG spec, the contents of the first <legend> of a <fieldset> should not be disabled when that fieldset is disabled.
One would expect that if an element does not appear disabled, its events will be triggered.
I've checked that on:
It looks like described bug only appears on Firefox. In addition when you uncheck checkbox on Edge 18 it becomes disabled and you cannot change its state again.
@bvaughn If you think it is a ReactJS bug and it could be good first issue then I would be glad if I could take it :)
I don't know enough about this part of React DOM to say whether it's something that React DOM should smooth over or just a browser bug. (Have you tried to see if this behavior can be reproduced in Firefox without React?)
Here I've created example that use pure Javascript and it works. As @MatthijsMud said - after second click on checkbox it doesn't execute onChange method and consequence of this is that enabled stays false so fieldset is always set to false after first checkbox click.
Seems like a bug then. Help yourself if you'd be interested in digging in, @ideffix :smile:
I've added the "good first issue (taken)" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let me know so that I can remove the label and free it up for someone else to claim.
Cheers!
I've done some digging and I ended up in EventListener.js and addEventBubbleListener function. It adds for document click event listener. However when HTML element(fieldset, input) is disabled it doesn't fire click event on Firefox. Please check this example both in Chrome and Firefox here. So it looks like Firefox bug/feature 馃槃
Nice follow up work, @ideffix!
Seems like maybe we should close this issue then and file one over on https://bugzilla.mozilla.org ?
Looks like this one is related, so maybe you could just add the info above to it?
https://bugzilla.mozilla.org/show_bug.cgi?id=1428838
Yes sure - I think we can close this :)
Thanks for the investigation then! 馃檱