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

Fix text contrast of disabled checkboxes #5155

Merged
merged 1 commit into from
Jul 31, 2024
Merged

Conversation

quis
Copy link
Member

@quis quis commented Jul 30, 2024

We have noticed that when checkboxes have the disabled attribute set1, the text does not meet WCAG standards2 for colour contrast. This is true for the label3, and worse for the hint text4.

This is caused by some CSS in GOV.UK Frontend5.

I propose:

  • using the secondary text colour for
    • the checkbox itself (which is inherited through currentColor)
    • the label text
    • the hint text
  • using a light grey fill to give an additional visual cue that the choice can’t be filled in by clicking it

This is the same thing we did for radio buttons in #4744


Before

image

After

image
  1. Using disabled is not often the best way to do things (and is not documented in the Design System) but sometimes it’s appropriate
  2. WCAG 2.0 AA requires a contrast ratio of 4.5:1 for ‘normal text’
  3. $govuk-text-colour with opacity: .5 applied computes to a value of #858585, which gives a contrast ratio of 3.69:1 against a white background
  4. $govuk-secondary-text-colour with opacity: .5 applied computes to a value of #a8acae, which gives a contrast ratio of 2.28:1 against a white background
  5. https://github.com/alphagov/govuk-frontend/blob/6271937e80f6147b7f3f1a248c47eb6d9f5a7061/packages/govuk-frontend/src/govuk/components/checkboxes/_index.scss#L138
  6. Colour alone isn’t used here to differentiate – there is the semantics of the disabled attribute itself, the different cursor behaviour, and the content of the hint text

We have noticed that when checkboxes have the `disabled` attribute
set[1], the text does not meet WCAG standards[2] for colour contrast.
This is true for the label[3], and worse for the hint text[4].

This is caused by some CSS in GOV.UK Frontend[5].

I propose:
- using the secondary text colour for
  - the checkbox itself (which is inherited through `currentColor`)
  - the label text
  - the hint text
- using a light grey fill to give an additional visual cue that the
  choice can’t be filled in by clicking it

***

This is the same thing we did for radio buttons in
https://github.com/alphagov/notifications-admin/pull/4744/files

***

1. Using `disabled` is not often the best way to do things (and is not
   documented in the Design System) but sometimes it’s appropriate
2. WCAG 2.0 AA requires a contrast ratio of 4.5:1 for ‘normal text’
3. `$govuk-text-colour` with `opacity: .5` applied computes to a value
   of  `#858585`, which gives a contrast ratio of 3.69:1 against a white
   background
4. `$govuk-secondary-text-colour` with `opacity: .5` applied computes to
   a value of  `#a8acae`, which gives a contrast ratio of 2.28:1 against
   a white background
5. https://github.com/alphagov/govuk-frontend/blob/6271937e80f6147b7f3f1a248c47eb6d9f5a7061/packages/govuk-frontend/src/govuk/components/checkboxes/_index.scss#L138
6. Colour alone isn’t used here to differentiate – there is the
   semantics of the `disabled` attribute itself, the different cursor
   behaviour, and the content of the hint text
@quis quis merged commit a8e8fd2 into main Jul 31, 2024
2 checks passed
@quis quis deleted the style-disabled-checkboxes branch July 31, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants