alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.17k stars 320 forks source link

Text colour for inverse button should use variable that indicates design intent #3918

Open paulrobertlloyd opened 1 year ago

paulrobertlloyd commented 1 year ago

Related component

Button component.

Version v4.7.0 introduced an inverse button modifier (yay!), but it's hard coded to use govuk-colour("blue"):

https://github.com/alphagov/govuk-frontend/blob/635bb3cb65f83ea4056353e276270595b4443add/packages/govuk-frontend/src/govuk/components/button/_index.scss#L39

However, it’s not clear if this is blue because govuk-brand-colour is blue, or because govuk-link-colour is blue. In most cases, this doesn't matter because backgrounds and links are both blue. But when the brand or link colours differ from the default, what should an inverse button look like? Should it:

Context

Alternatives

On the prototype masthead component, am considering whether to override the hardcoded Blue colour to share that of the masthead’s background: https://github.com/x-govuk/govuk-prototype-components/pull/134

Additional information (if applicable)

Happy with whatever design decision the Design System team come up with, but the colour in the codebase should indicate the design intent behind the colour chosen for inverse buttons; either govuk-brand-colour or govuk-link-colour (but not govuk-colour("blue")).

paulrobertlloyd commented 1 year ago

Accessibility consideration: the link text colour is (and should be) one that works with text on a white background. A brand colour is likely one that is chosen to work in large background areas and decorative borders, and may not have enough contrast when used for text. So I suspect the more robust choice is for the button text to share the colour of links.

querkmachine commented 1 year ago

Hmm, my concern is also that the brand colour has no guarantee of contrast when used against white—although the Notification Banner component appears to have already assumed it will, using $govuk-brand-colour on line 8 and hardcoding white text on top of it on line 33.

In my mind, we might want to do something like this:

Does that sound like it'd work for the use cases described here?

[^1]: To contrive a circumstance. A team wants to keep the inverse text colour as white, as they use it on non-brand colours too (like black), but white does not provide suitable contrast with the brand colour, so they need to change one or both of the inverse button variables specifically.

paulrobertlloyd commented 1 year ago

To underline the current issue, inverse button text may not match your brand colours, and if that brand colour is lighter, the inverse text colour won’t be accessible when sat upon it:

UI with current hard coded colour values

I think you’re right; hard-coding any of these exiting component colour values to either $govuk-brand-colour or $govuk-link-colour, while that might make this less of an issue, it would still be a problem with certain combinations.

Giving these values defaults that can be overridden globally, as you propose, seems like a brilliant solution!

Playing with that idea, all the following possible outcomes would be possible:

UI with customisable colour values