Bug: Events from an <input> in the <legend> of a disabled <fieldset> get supressed
See original GitHub issueThe closest related issue I could, is somewhat of the inverse of this one: #7711
React version: 16.12 (older versions as well)
Steps To Reproduce
- Create a component
- Add state indicating whether it is enabled or disabled (advised to start as enabled)
- On render, let the component return a
<fieldset>
with: a<legend>
containing an<input>
(checkbox) element, and another form element (<select>
,<input>
,<textarea>
). - Add the
disabled
attribute that follows the aforementioned state to the<fieldset>
. - Make the
onChange
event of the<input>
in the<fieldset>
responsible for modifying the state of the component (enabled/disabled). - Run an app that uses the described component.
- Disable the
<fieldset>
using the<input>
in its<legend>
. - (Try to) enable the
<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>;
}
The current behavior
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.
The expected behavior
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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
Checkbox in legend in disabled fieldset not firing
In a form I have a fieldset disabled by default. It has a legend and in that legend is a label with a...
Read more >1200127 - Disabled fieldset stops event bubbling from its legend
Actual results: Works one-way: fieldset is disabled and no event is received thereafter. Expected results: Such setup should allow toggling disabled state ...
Read more >Ext.form.field.Text | Ext JS 6.2.0 - Sencha Documentation
A list of event names that will be listened for on the field's input element, which will cause the field's value to be...
Read more >HTML 4 Transitional Document Type Definition - W3C
ENTITY % events " onclick %Script; #IMPLIED -- a pointer button was ... #REQUIRED -- server-side form handler -- method (GET|POST) GET --...
Read more >How to create a Form Wizard using jQuery Steps
On the other hand your visitors get frustrated because of the many page ... <fieldset>. <legend>Terms and Conditions</legend>. <input.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Seems like a bug then. Help yourself if you’d be interested in digging in, @ideffix 😄
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!
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.