Skip to content

[p5.js 2.0+ Bug Report]: createRadio().disable(false) does not re-enable radio inputs #9316

Open

Description

@slash-init

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.3.4

Web browser and version

firefox 157.0

Operating system

fedora

Steps to reproduce

  1. Open the p5.js Web Editor and select p5.js 2.3.4.
  2. Replace the sketch with the code below and run it.
  3. Wait one second for radio.disable(false) to execute.
  4. Observe that the radio buttons remain disabled and the status text reports Still disabled? true.

Expected behavior

Calling radio.disable(false) should re-enable the radio inputs, allowing the user to select an option again.

Actual behavior

The radio inputs remain disabled after radio.disable(false) is called.
The console shows that both inputs still have disabled === true, and their disabled attributes remain present with the string value "false".

Snippet

let radio;
let statusText;

function setup() {
  createCanvas(400, 120);

  radio = createRadio();
  radio.option('red');
  radio.option('blue');
  radio.position(20, 40);

  statusText = createP('Disabling radio buttons...');
  statusText.position(20, 65);

  radio.disable(true);

  setTimeout(() => {
    radio.disable(false);

    const inputs = radio._getOptionsArray();
    const stillDisabled = inputs.every(input => input.disabled);

    statusText.html(
      'Called disable(false). Still disabled? ' + stillDisabled
    );

    console.log(
      'Disabled properties:',
      inputs.map(input => input.disabled)
    );

    console.log(
      'Disabled attributes:',
      inputs.map(input => input.getAttribute('disabled'))
    );
  }, 1000);
}

function draw() {
  background(240);
}

Screenshot

p5.js Web Editor reproduction showing radio buttons remaining disabled after calling disable(false)

Additional context

The behavior appears to be caused by setting the HTML disabled attribute to a boolean value rather than updating the input's disabled state. HTML boolean attributes are enabled by their presence, regardless of the string value assigned to them.

The relevant implementation is in src/dom/dom.js, in self.disable, which iterates over the radio inputs and calls radioInput.setAttribute('disabled', shouldDisable).

A possible fix is to assign radioInput.disabled = shouldDisable, or otherwise remove the attribute when shouldDisable is false.

The reproduction was tested in the p5.js Web Editor using p5.js 2.3.4.

Activity

  1. MYMISERABLEMIND17 commented on Oct 22, 2026

    @MYMISERABLEMIND17

    Hey! I looked into this. In src/dom/dom.js, self.disable was calling radioInput.setAttribute('disabled', shouldDisable). When passing false, setting attribute disabled="false" still leaves the HTML boolean attribute present (so the browser still treats it as disabled) and does not update the radioInput.disabled DOM property.

    I updated self.disable to toggle radioInput.disabled = Boolean(shouldDisable) and properly add/remove the disabled attribute (removeAttribute('disabled') on false). I also added unit tests in test/unit/dom/dom.js verifying that disable(false) clears the attribute and sets disabled = false. All 118 DOM unit tests and linter pass cleanly.

    Could you please assign this issue to me so I can open the PR? Thanks!

  2. MYMISERABLEMIND17 commented on Oct 23, 2026

    @MYMISERABLEMIND17

    5. Hey! I looked into this. In src/dom/dom.js, self.disable was calling radioInput.setAttribute('disabled', shouldDisable). When passing false, setting attribute disabled="false" still leaves the HTML boolean attribute present (so the browser still treats it as disabled) and does not update the radioInput.disabled DOM property.
    I updated self.disable to toggle radioInput.disabled = Boolean(shouldDisable) and properly add/remove the disabled attribute (removeAttribute('disabled') on false). I also added unit tests in test/unit/dom/dom.js verifying that disable(false) clears the attribute and sets disabled = false. All 118 DOM unit tests and linter pass cleanly.
    Could you please assign this issue to me so I can open the PR? Thanks!

    any update ?

  3. slash-init commented on Oct 23, 2026

    @slash-init
    ContributorAuthor

    @MYMISERABLEMIND17 Thanks! Please wait for a maintainer to assign the issue to you before getting started.

  4. MYMISERABLEMIND17 commented on Oct 23, 2026

    @MYMISERABLEMIND17

    thanks

    7. @MYMISERABLEMIND17 Thanks! Please wait for a maintainer to assign the issue to you before getting started.

    okay

  5. added a commit that references this issue on Oct 26, 2026
    5a14592
  6. aryanb1906 commented on Oct 26, 2026

    @aryanb1906

    I've submitted a PR fixing this: #9338. The issue is that setAttribute('disabled', false) keeps the attribute present (HTML boolean attributes are active regardless of their value). Switching to the DOM property (radioInput.disabled = shouldDisable) fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions