jsdom icon indicating copy to clipboard operation
jsdom copied to clipboard

bug: `<fieldset>` considered `:disabled` if it contains `<legend>`

Open ph-fritsche opened this issue 4 years ago • 4 comments

Basic info:

  • Node.js version: v12.16.1
  • jsdom version: v17.0.0

Minimal reproduction case

https://replit.com/@PhilippFritsche/jsdom-pseudoclass#index.js

const { JSDOM } = require('jsdom')

const { window } = new JSDOM(`
  <fieldset>
    <legend>foo</legend>
  </fieldset>
`)

// should be null but is <fieldset>
console.log(window.document.querySelector(':disabled'))

How does similar code behave in browsers?

https://codesandbox.io/s/jsdom-pseudoclass-s1iub?file=/src/App.js

A <fieldset> is :disabled in JSDOM if it contains a <legend>. This is not the case in browsers.

ph-fritsche avatar Aug 24 '21 21:08 ph-fritsche

Perfect bug report, thank you!

Can you also check if window.document.querySelector("fieldset").disabled is true or false? That'd help narrow down whether it's a bug in jsdom, or a bug in our selector library.

domenic avatar Aug 24 '21 22:08 domenic

disabled property is false. Added it to the replit.

ph-fritsche avatar Aug 25 '21 06:08 ph-fritsche

This is affecting multiple of my unit tests as well. Really appreciate you filing this report @ph-fritsche

landonalder avatar Oct 11 '21 22:10 landonalder

I believe this was a bug in the nwsapi library, which wasn't correctly taking into account fieldset elements that do not have a legend. I've opened a PR that I think will fix this issue: https://github.com/dperini/nwsapi/pull/125

Example from my nwsapi changes:

Image

And before my changes: (fieldset is incorrectly selected)

Image

camchenry avatar Aug 30 '24 15:08 camchenry