govuk-frontend icon indicating copy to clipboard operation
govuk-frontend copied to clipboard

Set the boolean `disabled` attribute consistently in the button component

Open 36degrees opened this issue 1 year ago • 2 comments

Remove the value from the attribute so that we're setting boolean HTML attributes consistently across all components – matching what we're doing in the radios, checkboxes and select components.

Re-enable the 'attribute-boolean-style' rule so that we enforce this going forward.

Split out from #2828.

36degrees avatar Sep 07 '22 15:09 36degrees

As flagged in https://github.com/alphagov/govuk-frontend/pull/2828#discussion_r963437018, there are a few edge cases where this could be considered a breaking change.

Specifically, if a user is using getAttribute and relying on the value of the response either exactly matching the string 'disabled' or being truthy:

if ($button.getAttribute('disabled') == 'disabled') {
  // no longer works as getAttribute('disabled') on an element
  // with <button disabled> returns an empty string
}

if ($button.getAttribute('disabled')) {
  // no longer works as an empty string is falsey
}

Depending on how likely we think this scenario is, we could either:

  • accept the risk and include the change in the next minor release
  • consider making this change in the next major release
  • close this PR and avoid making this change

36degrees avatar Sep 07 '22 15:09 36degrees

Another thing that the change may break besides app using JS to check if the button is disabled may be the fixtures for validating non JS implementations.

Rails outputs boolean attributes in the disabled="disabled" form, I believe. Through its button_tag helper, for example.

romaricpascal avatar Sep 07 '22 15:09 romaricpascal