question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Events from an <input> in the <legend> of a disabled <fieldset> get supressed

See original GitHub issue

The 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

  1. Create a component
  2. Add state indicating whether it is enabled or disabled (advised to start as enabled)
  3. On render, let the component return a <fieldset> with: a <legend> containing an <input> (checkbox) element, and another form element (<select>, <input>, <textarea>).
  4. Add the disabled attribute that follows the aforementioned state to the <fieldset>.
  5. Make the onChange event of the <input> in the <fieldset> responsible for modifying the state of the component (enabled/disabled).
  6. Run an app that uses the described component.
  7. Disable the <fieldset> using the <input> in its <legend>.
  8. (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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
bvaughncommented, Jan 26, 2020

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!

1reaction
ideffixcommented, Jan 26, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found