Problem/Motivation

This is a fairly standard light mode disabled checkbox:
Light Mode Disabled Checkbox

Disabled checkbox in dark mode:
Dark Mode Disabled Checkbox

You can't differentiate visually between the disabled or enabled checkbox.

Steps to reproduce

  1. Go to /admin/modules/uninstall
  2. Switch between light/dark mode
  3. Confirm that it is difficult to see disabled elements

Also note you can test this with https://www.drupal.org/project/form_style

Proposed resolution

Add the CSS to make this stand out better.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3617875

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mgifford created an issue. See original summary.

mgifford’s picture

Disabled controls are legitimate HTML, and poorly styled disabled controls will remain a Drupal accessibility problem.

mgifford’s picture

StatusFileSize
new46.6 KB
new47.84 KB

I'm not sure this is the best approach, but worth putting it out for consideration.

Light Alternative with / through checkbox
Dark Alternative with / through checkbox

/* 1. Define variables for both modes */
:root {
  --control-disabled-text: #5C6670;
  --control-disabled-border: #87909A;
  --control-disabled-background: #E7E9EB;
}

[data-drupal-theme="dark"] {
  --control-disabled-text: #AEB6BF;
  --control-disabled-border: #76818C;
  --control-disabled-background: #30363D;
}

/* 2. Target only form-related elements to prevent affecting layout containers like .region-sticky__items__inner */
input:disabled, 
button:disabled, 
select:disabled, 
textarea:disabled,
[role="checkbox"][aria-disabled="true"],
[role="button"][aria-disabled="true"] {
  color: var(--control-disabled-text);
  border-color: var(--control-disabled-border);
  
  /* Layered background: Red line (gradient) on top of the dynamic background color */
  background: 
    linear-gradient(to top left, transparent calc(50% - 1px), red 50%, transparent calc(50% + 1px)),
    var(--control-disabled-background);

  /* CRITICAL: Allows the gradient to render on native checkbox/radio inputs */
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--control-disabled-border);
  display: inline-block;
  vertical-align: middle;
}

/* 3. Accessibility: Windows High Contrast Mode support */
@media (forced-colors: active) {
  input:disabled, button:disabled, [aria-disabled="true"] {
    forced-color-adjust: auto;
    color: GrayText;
    border-color: GrayText;
    background: none; /* Gradients are usually disabled in HCM for clarity */
  }
}
mgifford’s picture

The red line on black probably doesn't meet color contrast....

mherchel’s picture

It's also not the right size 🤷‍♂️

mgifford’s picture

Status: Active » Needs work
StatusFileSize
new4.77 KB

I failed to create a MR again, so just uploaded this patch. I may have luck with GitLab tomorrow.

gareth.poole made their first commit to this issue’s fork.

gareth.poole’s picture

Still unable to create a MR from the drupal-3617875 fork.

I added a similar diagonal strike as above using the border color (with linear gradient), this may be too subtle though.

controls light

controls dark

mherchel’s picture

StatusFileSize
new678.03 KB
new669.37 KB

I took a stab at it. I changed around the brightness of the backgrounds and borders. I also actually brightened up the border for the enabled text input, to differentiate it a bit more.

Before

After

mherchel’s picture

StatusFileSize
new129.94 KB
new154.58 KB

Here are some gifs so the changes are easily apparent.


mherchel’s picture

Issue summary: View changes
Status: Needs work » Needs review

Note I updated https://www.drupal.org/project/form_style to have lots of disabled elements, so you can easily test this yourself

gareth.poole’s picture

StatusFileSize
new56.43 KB
new57.75 KB

mherchel changed the visibility of the branch 3617875-better-dark-mode to hidden.

mherchel’s picture

Discussed with @mgifford and @jurgenhaas earlier today.

We went over the pros and cons of different branches and settled on the work that I did. We decided that the strike-through of the checkbox is not a normal pattern, so we're not doing that. We tried out other variations of gray, and even white, and decided that the current colors are sufficient and we're not going to do much better.

There was were minor issues: 1) The disabled checkboxes still had a hover state, and 2) the toggle checkbox's label didn't have the disabled color.

These have been fixed, and this should be good to go.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

This is an improvement. Thanks! I do think that there will be better patterns for enabled/disabled form elements at some point, but until there is some emerging consensus, I think this is a step forward. Disabled elements should be visible, should be clearly be different than enabled elements.

Adrian's point here is good https://adrianroselli.com/2024/02/dont-disable-form-controls.html

Don't disable form elements. But there are times when it is needed.

A possible follow-up from https://uxknowledgebase.com/the-disabled-state-in-ui-design-8c091d72868 is:

Add cursor: not-allowed, it is an additional visual cue

More reading on disabled elements for those who are keen:

  • catch committed 25a74d9d on 11.x
    fix: #3617875 Better Dark Mode Support for Disabled Elements
    
    By:...

  • catch committed 41b0b4ea on main
    fix: #3617875 Better Dark Mode Support for Disabled Elements
    
    By:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and 11.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

catch’s picture

Version: main » 11.x-dev
mherchel’s picture

Status: Fixed » Patch (to be ported)

  • mherchel committed 21ca2cb4 on 11.4.x authored by catch
    fix: #3617875 Better Dark Mode Support for Disabled Elements
    
    By:...
mherchel’s picture

Status: Patch (to be ported) » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.