Skip to content

USWDS - Accordion: Add color settings#5269

Merged
thisisdano merged 25 commits into
developfrom
jm-accordion-background
Jun 5, 2023
Merged

USWDS - Accordion: Add color settings#5269
thisisdano merged 25 commits into
developfrom
jm-accordion-background

Conversation

@mejiaj

@mejiaj mejiaj commented May 3, 2023

Copy link
Copy Markdown
Contributor

Summary

Customizable accordion colors. You can now customize the accordion button and background color settings.

Breaking change

This is not a breaking change.

Related issue

Closes #5249.

Related pull requests

Need to:

  • Add new settings to documentation
  • Add changelog entries

Documentation updates PR

uswds/uswds-site#2081

Preview link

Preview link:

Problem statement

Accordion background colors weren't configurable. Users had to add their own CSS overrides to customize the look and feel of accordions.

Solution

Two new accordion color settings:

Name Default Type Description
$theme-accordion-background-color default color The content background color.
$theme-accordion-button-background-color base-lightest color The button background.

Major changes

You can now change background colors in accordion. Accessible icons and text color are set on both default & hover state.

Note
This also affects Banner & Header, which use the accordion too.

Full list of changes

  1. New settings. Added two new accordion color settings $theme-accordion-background-color & $theme-accordion-button-background-color.
  2. Auto a11y text & background. Set accordion button and content color with set-text-and-bg mixin.
  3. New function to determine which icon to use. Create is-color-dark() function to determine if color is light or dark. Used for determining icon color set. Taken from checkbox-and-radio-colors.scss.
  4. New mixin for setting SVG icons as a background image. The mixin set-icon-from-bg checks the grade of the background color passed and sets a white/black icon. ⚠️ Note: this assumes a fallback icon exists in usa-icons-bg.

Testing and review

  1. Visit default preview Accordion (all variants)
  2. There should be no visual regressions
  3. Visit uswds/uswds-sandbox at test-uswds-5269 - preview link
  4. Accordions should be themable ― try several colors for $theme-accordion-button-background-color.
  5. Colors must pass contrast.
  6. Icons must pass contrast.
  7. npm run test:sass must pass [e7d695b].
  8. There should be no visual regressions in components that rely on accordion - Accordion/Banner/Header test.
  9. Visit _usa-checkbox.scss and uncomment lines 108-113.
  10. There should be no regressions in checkbox test story.

Additional tests

Click to expand to see results for previously problematic colors: yellow-20v, cyan-40, green-40. These colors were mentioned in thread below.

yellow-20v #face00

Settings

$theme-accordion-background-color: "yellow-5v",
$theme-accordion-border-color: "yellow-20v",
$theme-accordion-button-background-color: "yellow-20v",

image

cyan-40 #449dac

Settings

$theme-accordion-background-color: "cyan-60",
$theme-accordion-border-color: "cyan-40",
$theme-accordion-button-background-color: "cyan-40",

image

green-40 #7d9b4e

Settings

$theme-accordion-background-color: "green-70",
$theme-accordion-border-color: "green-40",
$theme-accordion-button-background-color: "green-40",

image

James Mejia added 2 commits May 3, 2023 09:31
- Add context variable
- Use set-text-and-bg mixin to set accessible text on user backgrounds
- Pass new background setting to accordion button & content
@mejiaj
mejiaj marked this pull request as ready for review May 3, 2023 16:39
@mahoneycm mahoneycm self-assigned this May 4, 2023

@mahoneycm mahoneycm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Variables are working like a charm!

I happened to notice one color wasn't setting the appropriate color icon, as well as a high contrast discrepancy we might want to address.


  • Confirmed no visual regression for accordion
  • Tested setting custom accordion theme colors
  • Text color updates and passes color contrast
  • Icon color updates and passes color contrast
    • Found failure with yellow-20v.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this as a function! Good thinking here

Comment thread packages/usa-accordion/src/styles/_usa-accordion.scss Outdated
Comment thread packages/usa-accordion/src/styles/_usa-accordion.scss Outdated
@mahoneycm mahoneycm removed their assignment May 4, 2023

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the added functionality here! I found a couple of issues and added notes below. Let me know if you have questions!

Tests performed:

  • Confirmed that the content background color is configurable with $theme-accordion-background-color
  • Confirmed that the button background color is configurable with $theme-accordion-button-background-color
  • Tested background colors of each grade (0-100) and confirmed that it correctly presents text and icon colors with acceptable color contrast
    • The icon does not always return the correct color. See this comment for details.
    • This is probably a separate issue, but I am not able to set background colors of grade 100: both “black” and “gray-100” throw errors
  • Confirmed that hover states on usa-accordion__button work as expected
  • Confirmed that there are no visual regressions with base styles

Comment thread packages/uswds-core/src/styles/functions/color/is-input-darkmode.scss Outdated
@mejiaj
mejiaj requested review from amyleadem and mahoneycm May 15, 2023 20:37
width: 100%;
}

// scss-lint:disable PropertyCount

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed scss-lint:disable PropertyCount because I wasn't seeing the error anyways.

true,
false
);
$input-darkmode: is-color-dark($input-bg-color);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The new function loads via @use "../../functions" as *; import on line 4.

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good so far. I like set-icon-from-bg.

I am not fully done with my review (planning on coming back tomorrow to finish up), but wanted to share these items in the meantime:

  1. A small question about is-color-dark
  2. Found a contrast issue in the checkbox component.

Let me know if you have questions!

Comment thread packages/uswds-core/src/styles/functions/color/is-color-dark.scss Outdated
Comment thread packages/uswds-core/src/styles/mixins/helpers/checkbox-and-radio-colors.scss Outdated

@mahoneycm mahoneycm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking great on my end! I was able to confirm the checkbox bug @amyleadem discovered but I did not find any other errors.

  • Flagged colors with existing issues now showing the proper icon color
  • mint-cool-30v which was also having the same failure is now showing the proper color icon
  • Unable to reproduce error with other colors
  • Tests pass automated testing

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, everything else is looking good except for the items flagged in yesterday's review! I had one additional question about an error message or fallback for set-icon-from-bg, but I don't think it needs to block anything.

Comment thread packages/uswds-core/src/styles/mixins/helpers/set-icon-from-bg.scss
@mejiaj
mejiaj requested review from amyleadem and mahoneycm May 24, 2023 19:47
/// @param {type} $icon-light - Light icon variant.
/// @output - A light or dark icon depending on the $background-color.
@mixin set-icon-from-bg($background-color, $icon-dark, $icon-light) {
$is-text-dark: is-color-dark($background-color);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just checking - is this a more appropriate name?

Suggested change
$is-text-dark: is-color-dark($background-color);
$is-background-dark: is-color-dark($background-color);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, changing would add clarity. Updated in e48dacc.

@amyleadem

Copy link
Copy Markdown
Contributor

Also, is it safe to remove the following items from the testing section of the PR description?

  1. Visit _usa-checkbox.scss and uncomment lines 108-113.
  2. There should be no regressions in checkbox test story.

@mejiaj

mejiaj commented May 24, 2023

Copy link
Copy Markdown
Contributor Author

Also, is it safe to remove the following items from the testing section of the PR description?

  1. Visit _usa-checkbox.scss and uncomment lines 108-113.
  2. There should be no regressions in checkbox test story.

@amyleadem I've added strikethrough to preserve the record, thanks for that note.

@mejiaj
mejiaj requested a review from amyleadem May 24, 2023 20:51
amyleadem
amyleadem previously approved these changes May 24, 2023

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved!

@mahoneycm mahoneycm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Happy to have this addition to the design system! 💯

  • Default accordion state is free of visual regression
  • Custom color variables correctly update accordion button, border, and content backbground colors
  • Text and icons are updated to offer appropriate color contrast despite the background colors including hover states
  • npm run test:sass passes

@mejiaj
mejiaj marked this pull request as draft May 25, 2023 17:18
@mejiaj

mejiaj commented May 25, 2023

Copy link
Copy Markdown
Contributor Author

@mahoneycm @amyleadem I've removed setting icons on hover because it was causing regressions in USA Banner & Header, which rely on usa-accordion [9d73f31]. The original intent on this was to double-check interactive states passed contrast.

I've also created a new test to help avoid these types of issues in the future.

@mejiaj
mejiaj marked this pull request as ready for review May 25, 2023 20:54
@mejiaj
mejiaj requested review from amyleadem and mahoneycm May 25, 2023 20:55
@amyleadem

amyleadem commented May 25, 2023

Copy link
Copy Markdown
Contributor

Confirming that I see the regression on hover for both banner and header. @mejiaj let me know if there are others I missed. Some examples of the regression:

Banner (at desktop widths)
image

Banner (at mobile widths)
image

Header (at mobile widths)
image

Note: the icon is white in these examples because I was testing with a color of grade 40. With default colors the icon will appear black.

With this update, the accordion button icon and text will have mismatched colors when it transitions from a "light" background to a "dark" one. As an example, this is what setting $theme-accordion-button-background-color with mint-40 looks like when it changes to mint-50 on hover:

image

Does it make sense to maintain the hover checks in accordion and then override the accordion background image on hover for the banner and header(ex: remove background image on .usa-banner__button[aria-expanded=false]:hover). It is not the prettiest but seems to fit the current code pattern.

@amyleadem
amyleadem dismissed their stale review May 25, 2023 23:03

Dismissing my previous review because changes have been made

@mejiaj

mejiaj commented May 30, 2023

Copy link
Copy Markdown
Contributor Author

@amyleadem thanks for confirming. I've added your suggestions.

  • Added back accordion icon setting on hover [e76526b].
  • Unset the icons on hover for Banner & Nav [95de5f9].

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! Performed the following tests:

  • Confirmed that accordion button text and icon colors match on hover when $theme-accordion-button-background-color is set to a color of grade 40
  • Confirmed that there are no regressions in banner or header

@thisisdano
thisisdano merged commit 100e162 into develop Jun 5, 2023
@amyleadem amyleadem mentioned this pull request Jun 7, 2023
@mejiaj
mejiaj deleted the jm-accordion-background branch July 18, 2023 16:52
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.

USWDS - Feature: accordion background should be configurable

4 participants