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

Setting disabled to false on a Button throws TypeError: null is not an object #1010

Closed
maxmilton opened this issue Aug 4, 2023 · 0 comments · Fixed by #1011
Closed

Setting disabled to false on a Button throws TypeError: null is not an object #1010

maxmilton opened this issue Aug 4, 2023 · 0 comments · Fixed by #1011
Labels
bug Something isn't working

Comments

@maxmilton
Copy link
Contributor

Describe the bug
Setting a button.disabled = false throws the error TypeError: null is not an object when the button is not already disabled.

To Reproduce

  1. Create a file button.mjs:
import { GlobalWindow } from 'happy-dom';

const window = new GlobalWindow();
const document = window.document;

const button = document.createElement('button');
button.disabled = false;
  1. Run node ./button.mjs
  2. See error

Expected behavior
Setting a button disabled attribute to false works as expected, regardless if the attribute is already present or not.

Screenshots
Terminal output:

~/P/repro-happy-dom  ❱ node ./button.mjs 
file:///home/max/Projects/repro-happy-dom/node_modules/happy-dom/lib/nodes/html-button-element/HTMLButtonElementNamedNodeMap.js:28
        if ((removedItem.name === 'id' || removedItem.name === 'name') &&
                         ^

TypeError: Cannot read properties of null (reading 'name')
    at HTMLButtonElementNamedNodeMap.removeNamedItem (file:///home/max/Projects/repro-happy-dom/node_modules/happy-dom/lib/nodes/html-button-element/HTMLButtonElementNamedNodeMap.js:28:26)
    at HTMLButtonElement.removeAttribute (file:///home/max/Projects/repro-happy-dom/node_modules/happy-dom/lib/nodes/element/Element.js:565:25)
    at set disabled [as disabled] (file:///home/max/Projects/repro-happy-dom/node_modules/happy-dom/lib/nodes/html-button-element/HTMLButtonElement.js:68:18)
    at file:///home/max/Projects/repro-happy-dom/button.mjs:7:17
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.4.0

Device:

  • OS: Linux 6.4.7-arch1-1 x86_64
  • happy-dom version: 10.7.0

Additional context
Only an issue when the button is not already disabled e.g., this works without error:

...

button.disabled = true;
button.disabled = false;
@maxmilton maxmilton added the bug Something isn't working label Aug 4, 2023
maxmilton added a commit to maxmilton/happy-dom that referenced this issue Aug 4, 2023
capricorn86 pushed a commit to maxmilton/happy-dom that referenced this issue Aug 4, 2023
capricorn86 pushed a commit to maxmilton/happy-dom that referenced this issue Aug 4, 2023
capricorn86 added a commit that referenced this issue Aug 4, 2023
#1010@patch: Check HTMLButtonElementNamedNodeMap removedItem is defined before accessing properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant