Skip to content

Conversation

@bjarnef
Copy link
Contributor

@bjarnef bjarnef commented Oct 19, 2025

Description

This fixes #653 where the checkmark at some colors has too low contrast and for some colors almost impossible to see: #653 (comment)

Keep in mind value can be any string value, when color property is used and color can be rgb or gradient color as well.

It may not solve every use-case e.g. for gradient and rgba colors with transparency, but work a bit better for solid colors as in Umbraco backoffice swatches and swatches in icon picker.

The chech color probably shouldn't rely on the color itself as it may contain alpha, and the more transparency, the more invisible the checkmark is.

GpMxWax2Or.mp4

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Motivation and context

How to test?

Screenshots (if appropriate)

Checklist

  • If my change requires a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

Copilot AI review requested due to automatic review settings October 19, 2025 12:10
@github-actions
Copy link

Hi there @bjarnef, thank you for this contribution! 👍

While we wait for the team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves accessibility by implementing dynamic contrast adjustment for checkmark icons in color swatches to ensure they remain visible against all background colors.

  • Adds automatic contrast detection logic to determine optimal checkmark color
  • Updates color swatch styles to apply dark or light filters based on background color contrast
  • Updates story examples with a more diverse set of colors to better demonstrate the contrast feature

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/uui-color-swatch/lib/uui-color-swatch.element.ts Implements contrast detection algorithm and applies dynamic styling to checkmark icons
packages/uui-color-swatches/lib/uui-color-swatches.story.ts Updates example colors to showcase the contrast feature with varied color values

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


#contrast(hex: string): string {
const rgb = this.#hexToRgb(hex);
const o = Math.round((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000);
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic numbers 299, 587, 114, and 1000 should be extracted as named constants to explain they represent the RGB to grayscale conversion coefficients and divisor.

Copilot uses AI. Check for mistakes.
const rgb = this.#hexToRgb(hex);
const o = Math.round((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000);

return o <= 180 ? 'dark' : 'light';
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 180 should be extracted as a named constant like 'LUMINANCE_THRESHOLD' to clarify its purpose as the brightness cutoff for determining contrast.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 19, 2025

Added an example with the blue #1e91e6 and orange #fa6419 colors from a concrete project, where the checkmark is grey'ish and difficult to see, because of the CSS filter contrast from swatch color.

Besides that I also think it makes sense to add a border + margin to make it more clear for current selection - but also just navigating though swatches via keyboard and the outline focus on swatch.
Another option may be to add inset border as this examples here: https://opensource.adobe.com/spectrum-web-components/components/swatch/

image image

We may also neeed to consider the look inside color picker.

image

Since the uui-color-swatch now allow a background (instead for previously background color), it should also be possible to use a background image, perhaps "army" or something else in a custom extensions like the example here.

image

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 20, 2025

@iOvergaard @nielslyngsoe do you have any thoughts regarding this?

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.

uui-swatch: checkmark has too low contrast on light colors

1 participant