question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update background color of selected List View item to meet contrast ratio requirement

See original GitHub issue

Describe the bug

Selected ListViewItems do not currently meet the 3:1 contrast ratio requirement relative to unselected items, as specified in MAS 1.4.11 - Non-text Contrast.

The selected color needs to be lighter in dark theme (currently it’s 2.2:1): image

The selected color needs to be darker in light theme (currently it’s 1.8:1): image

Additional context

Copied in part from an internal bug

Related to #1233

Proposed fix

https://github.com/microsoft/microsoft-ui-xaml/issues/2908#issuecomment-659632415

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:25 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
Felix-Devcommented, Jul 16, 2020

I would add the proposed brush like this then if nobody else is currently working on it:

<ResourceDictionary x:Key="Light">
    <SolidColorBrush x:Key="SystemControlHighlightListAccentMediumLowBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.75" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
    <SolidColorBrush x:Key="SystemControlHighlightListAccentMediumLowBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.75" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
    <SolidColorBrush x:Key="SystemControlHighlightListAccentMediumLowBrush" Color="{ThemeResource SystemColorHighlightColor}" />
</ResourceDictionary>

<StaticResource x:Key="ListViewItemBackgroundSelected" ResourceKey="SystemControlHighlightListAccentMediumLowBrush" />

@YuliKl As for the color contrast between selection rets and selection hover states in dark mode: Could we follow the color scheme used by the default button? button-dark

In our ListView case, that could for example look like this then: listviewitem-dark-proposed

We would use the following brushes here:

<StaticResource x:Key="ListViewItemBackgroundSelected" ResourceKey="SystemControlHighlightListAccentMediumLowBrush" />
<StaticResource x:Key="ListViewItemBackgroundSelectedPointerOver" ResourceKey="SystemControlHighlightListAccentLowBrush" />
<StaticResource x:Key="ListViewItemBackgroundSelectedPressed" ResourceKey="SystemControlHighlightListAccentHighBrush" />

<SolidColorBrush x:Key="SystemControlHighlightListAccentMediumLowBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.75" />
<SolidColorBrush x:Key="SystemControlHighlightListAccentLowBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.6" />
<SolidColorBrush x:Key="SystemControlHighlightListAccentHighBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.9" />

We would thus use your proposed brush for the the selection rest state and use the former brush used in the selected rest state (with opacity 0.6) now for the selected hover state. The brush used for the selected pressed state would remain unchanged. Effectively, we will have these opacity differences:

  • selected rest: 0.75
  • selected hover: 0.6 (this is 0.8 currently)
  • selected pressed: 0.9

Would reusing the former selected rest brush with opacity 0.6 for the selected hover state be a valid 3:1 contrast ratio concern relative to unselected ListViewItems as well?

(The brushes used in Light mode and High-contrast mode would also remain unchanged as of now.)

1reaction
StephenLPeterscommented, Aug 5, 2020

@StephenLPeters Have you heard any concerns about moving Common_themeresources to the CommonStyles folder?

I haven’t heard concerns and I think updating it would make sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change background color of selected item on a ListView
I want to know on how I can change the background color of the selected item on my listView. I only want to...
Read more >
Understanding Success Criterion 1.4.3: Contrast (Minimum)
Providing a minimum luminance contrast ratio between the text and its background can make the text more readable even if the person does...
Read more >
How to improve non-text contrast: color schemes and interface ...
When selecting colors, ensure there is at least a 3:1 contrast ratio between a color and its neighboring colors. If color is required...
Read more >
Text elements must have sufficient color contrast against ...
Checks all text elements to ensure that the contrast between the foreground text and the background colors meet the WCAG 2 AA contrast...
Read more >
background-color - CSS: Cascading Style Sheets | MDN
Color contrast ratio is determined by comparing the luminance of the text and background color values. In order to meet current Web Content ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found