Problem/Motivation
Olivero overrides the style for the ::selection pseudo-element:
/* base.pcss.css */
::selection {
color: white;
background-color: var(--color--blue-20);
}
I can't see a good justification for this, and other core themes don't do this.
Unless there's a very good reason to style it ourselves, it's best left to user-agents to decide. The selection indicator is a tool which really belongs to the user (not the author), rather like the mouse pointer. Cosmetics isn't a good reason here.
Steps to reproduce
Proposed resolution
Remove the ::selection styling from base.pcss.css (and the processed base.css).
Remaining tasks
None.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | After--patch-2.jpg | 24.24 KB | ranjith_kumar_k_u |
| #7 | After--patch-1.jpg | 18.92 KB | ranjith_kumar_k_u |
| #6 | 3196425-6.patch | 832 bytes | andrewmacpherson |
Comments
Comment #2
andrewmacpherson commentedComment #3
andrewmacpherson commentedThe only other place where Drupal core styles selected text is in the off-canvas dialog. I've filed a separate issue for that - #3196430: Remove ::selection style from off-canvas dialog reset.
Comment #4
gauravvvv commentedI have removed the ::selection pseudo element from css file. I have provided the patch please verify if it is working or not.
Comment #5
gauravvvv commentedComment #6
andrewmacpherson commentedHi @Gauravmahlawat - thanks for looking at this issue.
.pcss.cssfile. It also needs to update the processed.cssfile. See Drupal core using PostCSS for development for the necessary steps to do that.However, I'd already done the necessary work in the patch on comment #2.
Re-posting the patch from #2 as the latest one for review (no interdiff needed).
Comment #7
ranjith_kumar_k_u commentedThe last patch applied cleanly and it removes the following css code


from "core/themes/olivero/css/base/base.css",
following css code
from "core/themes/olivero/css/base/base.pcss.css".
Comment #8
mherchelThe justification is the design itself. This styling was requested by the designers.
Does this cause any accessibility failures?
Comment #9
andrewmacpherson commentedIt affects accessibility in several ways, but not all covered by WCAG success criteria.
The main reason to avoid setting a
::selectioncolour is that it clobbers user preferences. The MDN article on ::selection has a section on accessibility concerns, and emphasizes: "Don't override selected text styles for purely aesthetic reasons — users can customize them to suit their needs". Here's how that works in practice. Most desktop operating systems offer a way for users to choose their own highlight colour for selected text:This is a big deal for users with dyslexia and/or attention impairments. Lots of people use the text highlight as a reading aid, and the ability to customize the colour is a very powerful tool. When an author stylesheet overrides the colours for
::selection, the browsers no longer respect the OS-level highlight colour.It also clobbers a cool feature of Firefox on Windows and Linux. The browser respects the OS highlight colour, but will dynamically invert it based on the background colour of the web content, to make it more likely that the highlight will hagve good contrast. So if your highlight colour is white-on-purple, it will be inverted to purple-on-white when the page background is dark. But when an author stylesheet overrides the
::selectioncolours, Firefox no longer applies this inversion feature.The selected text colour is in scope for WCAG SC 1.4.11 Non-text Contrast. Note that when this is determined by the user-agent, and not modified by the author, it is exempt from that success criterion.
But if we do override the selection colours, then they must have 3:1 contrast against the surrounding un-selected text. This is where the trouble starts, because Olivero is a general-purpose theme for a customizable CMS. We can't know what editor features are enabled, or background colours will be used in the content.
The CKEditor Colour Button module has ~18K installs. It lets editors set the foreground and background colours of text to anything, but doesn't offer any control over the
::selectioncolours. The blue currently specified in Olivero's stylesheet won't provide sufficient contrast against darker backgrounds, especially blues, greens, and purples.A more cautious site builder might provide colour choices by using a CKEditor stylesheet and limited classes. This way they could provide
::selectioncolours for all of their classes. However, that's extra work they didn't have to do with Bartik.Comment #10
andrewmacpherson commentedComment #12
andrewmacpherson commented@Lendude deserves a credit here too. They helped out with some macOS browser testing, when I asked in the Slack #contribute channel. My mac is broken so I needed someome to check whether browsers respect the user-specified highlight colour from macOS System Preferences. They confirmed that Firefox, Safari, Opera, and Chrome, all respect the macOS highlight colour choice unless the author stylesheet has overridden the colours of ::selection. If you are logged in to Slack, you can see a record of the contribution in this thread - https://drupal.slack.com/archives/C1BMUQ9U6/p1612515039234300
Comment #13
mherchelThanks for the clarification.
Patch in #6 looks perfect. Thanks!
Comment #15
mherchelPatch failed testing because of an unrelated reason. Latest test passes.
Comment #18
lauriiiCommitted 1ed4ffa and pushed to 9.2.x and 9.1.x. Thanks!