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

Update focus outline color to meet WCAG 2.2 contrast standards #6854

Merged
merged 20 commits into from
Jul 9, 2024

Conversation

evansjohnson
Copy link
Contributor

@evansjohnson evansjohnson commented Jun 18, 2024

Fixes no issue

Checklist

  • [n/a] Includes tests
  • Update documentation

Changes proposed in this pull request:

Update color of focus outline to meet 3:1 contrast standard for UI component focus states

https://webaim.org/resources/contrastchecker/

Reviewers should focus on:

  • Our default focus indicator won't meet contrast standards for arbitrary colors - but should we provide any buffer so that the default focus indicator meets standards up to a certain shade of background color, rather than just $white/$black?
    • I currently went with an option that meets contrast standards against all light-gray colors in light theme, and all dark-gray colors when in dark theme
  • Should be good in light and dark themes
  • Design review checklist

WCAG Guidelines

From what I can tell, WCAG did not require minimum contrast in 2.1, but in 2.2 has a section on focus appearance which specifies the 3:1 minimum ratio

Screenshot

Current:
Screenshot 2024-06-21 at 8 28 04 AM
Screenshot 2024-06-21 at 8 27 54 AM

This PR:
Screenshot 2024-06-21 at 8 28 04 AM
Screenshot 2024-06-21 at 8 27 54 AM

@changelog-app
Copy link

changelog-app bot commented Jun 18, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Update focus indicator colors to meet WCAG 2.2 contrast standards

Check the box to generate changelog(s)

  • Generate changelog entry

@svc-palantir-github

This comment was marked as outdated.

Copy link
Contributor Author

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

this feels like a borderline breaking change, since it has the potential to make UI snapshots fail. I don't think it could cause some cases to have worse contrast because the current focus color already does not have enough contrast with the extremes of the color spectrum

packages/core/src/components/forms/_common.scss Outdated Show resolved Hide resolved
packages/core/src/components/forms/_controls.scss Outdated Show resolved Hide resolved
@evansjohnson evansjohnson changed the title [WIP] Update focus outline color to meet contrast standards Update focus outline color to meet WCAG 2.2 contrast standards Jun 21, 2024
@svc-palantir-github

This comment was marked as outdated.

@svc-palantir-github

This comment was marked as outdated.

@evansjohnson

This comment was marked as duplicate.

@svc-palantir-github

This comment was marked as outdated.

packages/core/src/common/_color-aliases.scss Outdated Show resolved Hide resolved
Comment on lines 95 to 104
// this should become default in bp6, providing new behavior as a class for now to avoid breaking changes
// to focus colors
/* stylelint-disable-next-line @blueprintjs/no-prefix-literal */
.bp5-focus-enhanced-contrast & {
outline: $pt-focus-indicator-color solid 2px;
}
/* stylelint-disable-next-line @blueprintjs/no-prefix-literal */
.#{$ns}-dark.bp5-focus-enhanced-contrast & {
outline-color: $pt-dark-focus-indicator-color;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should just do it. I wouldn't call this a breaking change. If we do introduce this class, you should use #{$ns} instead of bp5, which is what this lint rule is trying to tell you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay cool, I wasn't sure the history of how careful we've been with minor things like this that could be viewed as a break.

Ack on the prefix - I hard coded bp5 since this was only intended to work for the bp5 version and removed in bp6, but will just remove this.

packages/core/src/docs/accessibility.md Outdated Show resolved Hide resolved
@svc-palantir-github

This comment was marked as outdated.

Copy link
Contributor Author

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

TODO:

  • Audit intent color contrast, pt-input-intent and pt-dark-input-intent

    • $pt-intent-colors
    • $pt-dark-input-intent-box-shadow-colors
  • Audit focus outline of all components (planning to leave out of this PR) - a few more here but highlighting some main ones:

  • [-] Check on history of why components that appear like text inputs have a shadow focus style while other components have offset outline style

    • For now, went with an option that retains box-shadow for text inputs, but styled in a way that makes it look closer to a solid outline. I figured this reduces chances of regressions since this will just change the color/opacity used but not the method of adding a focus indicator for these components.
  • Consider Consider using :focus-visible instead of :focus for styling focus states #6076 along with this PR, or as a follow up in the same release

    • This was already tagged a breaking change - we could consider at the next major version bump but not needed for now.

Comment on lines 95 to 104
// this should become default in bp6, providing new behavior as a class for now to avoid breaking changes
// to focus colors
/* stylelint-disable-next-line @blueprintjs/no-prefix-literal */
.bp5-focus-enhanced-contrast & {
outline: $pt-focus-indicator-color solid 2px;
}
/* stylelint-disable-next-line @blueprintjs/no-prefix-literal */
.#{$ns}-dark.bp5-focus-enhanced-contrast & {
outline-color: $pt-dark-focus-indicator-color;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay cool, I wasn't sure the history of how careful we've been with minor things like this that could be viewed as a break.

Ack on the prefix - I hard coded bp5 since this was only intended to work for the bp5 version and removed in bp6, but will just remove this.

packages/core/src/docs/accessibility.md Outdated Show resolved Hide resolved
packages/core/src/common/_color-aliases.scss Outdated Show resolved Hide resolved
@@ -25,6 +25,10 @@ $pt-app-elevated-background-color: $light-gray4 !default;
$pt-dark-app-elevated-background-color: $dark-gray3 !default;

$pt-outline-color: rgba($blue3, 0.6) !default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not changing this color because of the comment at the top of this file stating that is generally considered a breaking change. Perhaps we want to make an exception here...

@svc-palantir-github
Copy link

comment

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@@ -25,6 +25,11 @@ $pt-app-elevated-background-color: $light-gray4 !default;
$pt-dark-app-elevated-background-color: $dark-gray3 !default;

$pt-outline-color: rgba($blue3, 0.6) !default;
// 0.752 opacity to meet WCCAG 2.2 minimum contrast guidelines with all light-gray backgrounds in light theme
// and all dark-gray backgrounds in dark theme
$pt-focus-indicator-color: rgba($blue2, 0.752) !default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$blue2 on $white - 3.77:1 contrast
$blue2 on $light-gray1 - 3:1 contrast

// and all dark-gray backgrounds in dark theme
$pt-focus-indicator-color: rgba($blue2, 0.752) !default;
// dark theme opacity could be less and still meet minimum contrast, but keep 0.752 to stay consistent
$pt-dark-focus-indicator-color: rgba($blue5, 0.752) !default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$blue5 on $black - 5.77:1 contrast
$blue5 on $dark-gray5 - 3.39:1 contrast


for comparison - $blue4 on $dark-gray5 - 2.24:1 contrast

@@ -15,14 +15,14 @@ $input-color-disabled: $button-color-disabled !default;
$input-placeholder-color: $pt-text-color-muted !default;
$input-background-color: $white !default;
$input-background-color-disabled: rgba($light-gray1, 0.5) !default;
$input-shadow-color-focus: $pt-intent-primary !default;
$input-shadow-color-focus: $pt-focus-indicator-color;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if this can't be relied on externally - remove and use $pt-focus-indicator-color directly in the handful of places it's used. Same for dark theme version below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks like we explicitly distribute _colors.scss, _color-aliases and _variables, but not this file. could consider updating to use $pt-focus-indicator-color directly

"dist:variables": "generate-css-variables --retainDefault true ../../colors/src/_colors.scss common/_color-aliases.scss common/_variables.scss",

@svc-palantir-github
Copy link

input focus style

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

Add generated changelog entries

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

inset border-shadow(1, $color, 1px),
border-shadow(0.3, $color, 2px);
inset border-shadow(0.752, $color, 1px),
border-shadow(0.752, $color, $outer-shadow-focus-width);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

border-shadow width stayed the same in the case of intent shadows (since they already start with 1px in un-focused state, the focus state is a 3px shadow outline)

for non-intent inputs, the shadow width reduced by 1px. I expect this to mean that shadows that worked in previous situations will continue to work (ex there won't be clipping introduced from something like a new outline offset or wider shadow)

@@ -197,7 +197,6 @@ $control-indicator-spacing: $pt-grid-size !default;

input:focus ~ .#{$ns}-control-indicator {
@include focus-outline();
outline: $blue3 solid 2px;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

from what I can tell this was just to provide increased contrast, no reason to not use the consistent focus-outline style now

@@ -632,10 +631,6 @@ $control-indicator-spacing: $pt-grid-size !default;
background-color: $dark-control-background-color-hover;
}

input:focus ~ .#{$ns}-control-indicator {
outline: $blue5 solid 2px;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same comment as line 200 in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

colors have changed - but not the method of how the focus indicator is applied (2px offset 2px outline) so I expect minimal chance of breaking changes

@evansjohnson evansjohnson marked this pull request as ready for review July 1, 2024 15:22
@svc-palantir-github
Copy link

input group not form group

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@evansjohnson
Copy link
Contributor Author

Compare public docs vs latest "documentation" link from latest @svc-palantir-github comment

Design review checklist:

  • Light theme
    • Existing high contrast focus style components like Checkbox, Radio, Switch
    • Outline focus style on a few interactive components, like Button, Menu, Tabs
    • Text input styled components like InputGroup, NumericInput, EditableText
    • Text input styled components with intent
  • Dark theme
    • Existing high contrast focus style components like Checkbox, Radio, Switch
    • Outline focus style on a few interactive components, like Button, Menu, Tabs
    • Text input styled components like InputGroup, NumericInput, EditableText
    • Text input styled components with intent

@gluxon gluxon self-assigned this Jul 1, 2024
@alex-dales
Copy link
Contributor

Design review checklist:

  • Light theme

    • Existing high contrast focus style components like Checkbox, Radio, Switch
    • Outline focus style on a few interactive components, like Button, Menu, Tabs
    • Text input styled components like InputGroup, NumericInput, EditableText
    • Text input styled components with intent
  • Dark theme

    • Existing high contrast focus style components like Checkbox, Radio, Switch
    • Outline focus style on a few interactive components, like Button, Menu, Tabs
    • Text input styled components like InputGroup, NumericInput, EditableText
    • Text input styled components with intent

Looks good! Some comments and questions below:

Comments

  • Unrelated to the contrast changes, but I noticed that with the segmented control when an option between two other options is selected and we focus the left-most option, the focus border is behind the selected option. When we focus the right-most option this isn't the case. Could we fix the the focus for the left-most option here to not be clipped?

Left-most option focused
Screenshot 2024-07-01 at 3 19 20 PM

Right-most option focused
Screenshot 2024-07-01 at 3 19 25 PM

  • For a numeric input with intent and in light mode I noticed the input field overlaps the focus border of the right buttons. Could we fix this to bring the focus border to the front?

Screenshot 2024-07-01 at 3 54 31 PM

Questions

  • Do submenus intentionally have a non-rounded focus border? I was expecting that they'd also be rounded to be consistent with the focus state for menu items

Screenshot 2024-07-01 at 3 21 04 PM

  • Was just curious what was the rationale behind moving from the two-colored stroke to the single colored stroke for input fields? I do think it looks cleaner. Just wanted to flag that we still have the previous visual treatment for the border when the control card is in the selected state. I realize it is a different state, but should we also consider updating the control card here to be consistent?

Previous
Screenshot 2024-07-01 at 3 40 37 PM

New
Screenshot 2024-07-01 at 3 40 28 PM

Control card option selected
Screenshot 2024-07-01 at 3 42 32 PM

@evansjohnson
Copy link
Contributor Author

Ah great find on the ControlCard. I'll get that updated and do another second pass myself and look for others that may not be up to date.


Since this is already a delicate change to get released, I'd strongly prefer to track all of the border overlap and other issues noted separately, but am happy to continue to work on them, thanks for flagging explicit examples! For this PR I want to keep a close eye on making sure we don't have any regressions, but would expect existing bugs to remain in place for now. If any of the bugs are particularly bad in your opinion, and perhaps become even more obvious with the increased contrast, I could fix as needed as pre-requisites to this PR.


My thinking on moving to a solid border color is that we need to get much darker and 2px width to meet minimum contrast standards, and having 0.752 opacity right next to 1 opacity looks a little off in a way the previous light shadow didn't.

@alex-dales
Copy link
Contributor

Ah great find on the ControlCard. I'll get that updated and do another second pass myself and look for others that may not be up to date.

Sounds good!

...perhaps become even more obvious with the increased contrast, I could fix as needed as pre-requisites to this PR

I don't think these bugs are particularly blocking, so I think it is ok to tackle this in a FLUP PR so you can get these changes in.

My thinking on moving to a solid border color is that we need to get much darker and 2px width to meet minimum contrast standards...

Makes sense, I think the solid border also looks cleaner!

@evansjohnson
Copy link
Contributor Author

evansjohnson commented Jul 1, 2024

From the demo app it looks like there's some custom toast focus styles that look like they don't have high contrast
Screenshot 2024-07-01 at 6 24 11 PM

confirmed here:
Screenshot 2024-07-01 at 6 59 18 PM


current contrast bumping $white focus opacity to 0.75 from 0.5:
Screenshot 2024-07-01 at 6 51 01 PM
Screenshot 2024-07-01 at 6 50 41 PM
Screenshot 2024-07-01 at 6 50 23 PM
Screenshot 2024-07-01 at 6 50 03 PM


updating toast focus color to match text color with 0.75 opacity
Screenshot 2024-07-01 at 6 53 55 PM

Screenshot 2024-07-01 at 6 57 20 PM Screenshot 2024-07-01 at 6 57 11 PM

@evansjohnson
Copy link
Contributor Author

I'm wondering if we're conflating focus and selection styles and may be anchoring on the focus state because that's what this PR is changing. FWIW that style is not reused and is unique to ControlCard so this is just limited to the relatively new ControlCard component.


There is an argument to be made that the current selection state already follows the current focus state, so if we're updating one we should update the other. But I could also see this staying the same, since from what I've read so far this is a guideline for focus state which is more transient than a selection state and needs to grab the users attention.

@svc-palantir-github
Copy link

increase toast focus contrast

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@alex-dales
Copy link
Contributor

alex-dales commented Jul 2, 2024

Toast focuses look good!


Yeah agreed, I don't want to over-index on the control card selection state since it is different. After mocking up the 2px border for the selection state on the control card, I do like visually how the solid border looks – it is almost more attention-grabbing compared to the current. I'd be curious to get some more thoughts from the design team here, but this shouldn't be blocking for this PR!

Screenshot 2024-07-02 at 11 14 43 AM

@evansjohnson
Copy link
Contributor Author

Thanks for highlighting those existing issues! I opened #6890 and #6889 to track

@evansjohnson
Copy link
Contributor Author

Let me know if you end up wanting to change selected styles and we can make sure there's at least a ticket open to track

@svc-palantir-github
Copy link

Merge branch 'develop' into evanj/focus-indicator

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@@ -47,7 +47,7 @@ $toast-intent-colors: (

&:focus {
// blue outline color shows poorly on colored bg
outline-color: rgba($white, 0.5);
outline-color: rgba($text-color, 0.75);
Copy link
Member

Choose a reason for hiding this comment

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

Was this intentional? Seems odd to use the text color for the outline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left an exploration of this here: #6854 (comment)

The text color is what allows us to easily flip to a dark outline when rendering against a light color background. Alternate option to define a separate focus color variable, but I'm not sure what we'd really choose differently - these are already against intent backgrounds so it's a bit of a weird case.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not saying the color itself is weird, and choosing the same color seems fine. It's just odd to use the variable for text color for something that isn't text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes - updated to $text-and-focus-color, didn't think of anything good to combine them generically, ex $content-color doesn't sound right

invliD
invliD previously approved these changes Jul 9, 2024
@alex-dales
Copy link
Contributor

Let me know if you end up wanting to change selected styles and we can make sure there's at least a ticket open to track

Sorry, I missed this last week! Will let you know if we want to make a change here and FLUP as needed over Slack.

@policy-bot policy-bot bot dismissed invliD’s stale review July 9, 2024 20:16

Invalidated by push of f55fad6

@svc-palantir-github
Copy link

more descriptive var name

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@evansjohnson evansjohnson merged commit 0f5b88c into develop Jul 9, 2024
13 checks passed
@evansjohnson evansjohnson deleted the evanj/focus-indicator branch July 9, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants