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

[EuiAvatar] Calculate high-contrast text against background #7824

Open
daniel-rhoades opened this issue Jun 10, 2024 · 11 comments
Open

[EuiAvatar] Calculate high-contrast text against background #7824

daniel-rhoades opened this issue Jun 10, 2024 · 11 comments
Labels
accessibility help wanted The EUI team is looking for community members to pick up and implement this issue

Comments

@daniel-rhoades
Copy link

daniel-rhoades commented Jun 10, 2024

Summary

Within the Avatar component, for the purposes of rendering initials, the text colour is selected based either the selected or generated background colour:

const assignedColor =
color || visColors[Math.floor(name.length % visColors.length)];
const textColor = isColorDark(...hexToRgb(assignedColor))
? '#FFFFFF'
: '#000000';

Currently, the logic simplistically chooses white (for dark backgrounds) or black (for light backgrounds), this won't necessarily provide a sufficient contrast against some background colours. Neither is there support for explicitly setting the text colour.

A similar issue applies to the Badge component:

export const getTextColor = ({ euiTheme }: UseEuiTheme, bgColor: string) => {
const textColor = isColorDark(...chroma(bgColor).rgb())
? euiTheme.colors.ghost
: euiTheme.colors.ink;
return textColor;
};

Albeit inconsistent with Avatar, the Badge component does at least raise a contrast warning:

// Set dark or light text color based upon best contrast
const textColor = getTextColor(euiTheme, color);
// Check the contrast ratio. If it's low contrast, emit a console awrning
const contrastRatio = getColorContrast(textColor, color);
if (contrastRatio < wcagContrastMin) {
console.warn(
`Warning: ${color} badge has a low contrast of ${contrastRatio.toFixed(
2
)}. Should be above ${wcagContrastMin}.`
);
}

Acceptance Criteria

  1. Calculate an appropriate high-contrasting colour (WCAG AA compliant) based on the background colour
  2. (Optionally) expose an additional property to allow the colour to be overridden

Fortunately, an existing utility function already exists within the EUI component library for calculating an appropriate contrasting colour: makeHighContrastColor.

@cee-chen
Copy link
Member

@1Copenut Has this come up in any of our accessibility audits of Kibana?

@cee-chen cee-chen changed the title Avatar: Calculate high-contrast text against background [EuiAvatar] Calculate high-contrast text against background Jun 17, 2024
@JasonStoltz
Copy link
Member

Thank you for bringing it to our attention.

This is a valid accessibility issue, but not one we can prioritize at the moment.

We would accept a PR for this, however, which adds a simple color contrast detection and warning as seen in the Badge.

@JasonStoltz JasonStoltz added the help wanted The EUI team is looking for community members to pick up and implement this issue label Jun 18, 2024
Copy link

👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.

@Arup-Chauhan
Copy link

@JasonStoltz if no one is working on this issue, I would like to take it, I am new contributor to this repo, thanks!

@cee-chen
Copy link
Member

@Arup-Chauhan if an issue has not been assigned to an EUI team member, it's free to pick up by any open source contributor - simply open a PR against our repo. Please see our contributing guidelines for more! https://github.com/elastic/eui/tree/main/wiki/contributing-to-eui

@Arup-Chauhan
Copy link

Hi @cee-chen , sure, so would you be assigning me this issue to work upon?

Also, can I raise a draft PR to work on this issue? I have some initial questions on how to do it and also, I can get a feedback on my work underway.

@cee-chen
Copy link
Member

No, we do not assign issues to non-EUI contributors. Please see our linked wiki above again:

In general, once on Github, any issue can be worked on by the community. If you find an issue that is not assigned, assume that you are welcome to work on it and can submit a pull request. We recommend that you leave us a comment indicating your intent before starting work to avoid potential conflict. We do not, as a policy, assign issues to community members and we usually reserve larger projects or ones that are core to our roadmap or design to be done internally.

It also answers your question about draft PRs - they are very welcome. You will want to @ mention us in a comment for questions and requests for early feedback.

@Arup-Chauhan
Copy link

No, we do not assign issues to non-EUI contributors. Please see our linked wiki above again:

In general, once on Github, any issue can be worked on by the community. If you find an issue that is not assigned, assume that you are welcome to work on it and can submit a pull request. We recommend that you leave us a comment indicating your intent before starting work to avoid potential conflict. We do not, as a policy, assign issues to community members and we usually reserve larger projects or ones that are core to our roadmap or design to be done internally.

It also answers your question about draft PRs - they are very welcome. You will want to @ mention us in a comment for questions and requests for early feedback.

Oh, sure no problem, I will make a draft PR and get started, will ask questions there only, thanks!

Arup-Chauhan added a commit to Arup-Chauhan/eui that referenced this issue Jul 22, 2024
Signed-off-by: Arup Chauhan <[email protected]>
Arup-Chauhan added a commit to Arup-Chauhan/eui that referenced this issue Aug 31, 2024
@github-actions github-actions bot added the Stale label Oct 4, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
@Arup-Chauhan
Copy link

Arup-Chauhan commented Oct 11, 2024

@cee-chen I have added a comment in the draft PR for to this, can you please check it once?

@cee-chen
Copy link
Member

Please disregard the noise/issue closure - stalebot went rogue due to misconfiguration.

@cee-chen cee-chen reopened this Oct 14, 2024
@cee-chen cee-chen removed the Stale label Oct 14, 2024
@Arup-Chauhan
Copy link

Thanks @cee-chen , I will continue work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility help wanted The EUI team is looking for community members to pick up and implement this issue
Projects
None yet
Development

No branches or pull requests

4 participants