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

ContrastChecker: Add font size logic inside the component; Add additional test cases; #8059

Conversation

jorgefilipecosta
Copy link
Member

Contrast checker included logic to differentiate between large and small text. The logic is dependent on fontSize so it makes sense to have for normal cases logic that uses the fontSize inside ContrastChecker checker. The logic is not just dependent on fontSize (e.g: if text is bold for the same fontSize the contrast may be valid) we allow users of the component to still rely on isLargetext prop and decide by them selfs if the text they contain is considered large or not.

How has this been tested?

I created a paragraph I set the text color to "#C44B4B" and the background color to "#000000".
I checked that for font sizes medium an lower there is a contrast waring and for large font sizes, there is no contrast warning.

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Works well and the code lgtm. Thanks for adding tests.

I'm wondering if we should just eliminate the isLargeText prop altogether. It looks like it's only used in one place now:

isLargeText={ true }

We could replace this remaining usage with fontSize={ 18 } since we know that buttons have 18pt text per this line:

font-size: $big-font-size;

Anyway, not a blocker—totally up to you 🙂

Contrast checker included logic to differentiate between large and small text. The logic is dependent on fontSize so it makes sense to have for normal cases logic that uses the fontSize inside ContrastChecker checker. But because the logic is not just dependent on fontSize (e.g: if text is bold for the same fontSize the contrast may be valid) we allow users of the component to still rely on isLargetext prop and decide by them selfs if the text they contain is considered large or not.
@jorgefilipecosta jorgefilipecosta force-pushed the add/fontSize-comparation-logic-inside-contrast-checker branch from 4edac18 to f7d752e Compare July 20, 2018 10:38
@jorgefilipecosta
Copy link
Member Author

Hi @noisysocks thank you for the review. I think the property isLargeText should exist because as referred font size is not the only decision point if the text is bold for example it may be considered large with a different font size.
The isReadable function we are using, forces invokers to decide if the text is large or not. I think we should allow users of our component to do the same, but we can provide additional logic e.g: to avoid font size comparisons on the paragraph.
For the button case, I think because of the nature of the block the text there should always be considered large if not because of the font size it should be because of text being bold or something similar so in that case, I prefer to use isLargeText directly.

@jorgefilipecosta jorgefilipecosta merged commit 201be4b into master Jul 20, 2018
@jorgefilipecosta jorgefilipecosta deleted the add/fontSize-comparation-logic-inside-contrast-checker branch July 20, 2018 19:10
@pento pento added this to the 3.4 milestone Jul 30, 2018
@afercia
Copy link
Contributor

afercia commented Aug 1, 2018

@jorgefilipecosta thanks for your work on this! I have a question though: is the font size check based on pixels or points? Please notice that the WCAG requirement refers to points, not pixels. Reference:

https://www.w3.org/TR/WCAG21/#contrast-minimum

Large-scale text and images of large-scale text have a contrast ratio of at least 3:1;

"Large scale text" is defined in points, not pixels:
https://www.w3.org/TR/WCAG21/#dfn-large-scale

with at least 18 point or 14 point bold

The actual size of the character that a user sees is dependent both on the author-defined size and the user's display or user-agent settings. For many mainstream body text fonts, 14 and 18 point is roughly equivalent to 1.2 and 1.5 em or to 120% or 150% of the default size for body text (assuming that the body font is 100%), but authors would need to check this for the particular fonts in use.
etc...

So, calculating the actual point size may depend on various conditions. However, it's an (more or less) accepted practice to use 24 pixels and 18.5 pixels as values. This is explained in the WCAG "Understanding Success Criterion 1.4.3: Contrast (Minimum)":

https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html

When evaluating this success criterion, the font size in points should be obtained from the user agent or calculated on font metrics in the way that user agents do. Point sizes are based on the CSS pt size as defined in CSS3 Values. The ratio between sizes in points and CSS pixels is 1pt = 1.333px, therefore 14pt and 18pt are equivalent to approximately 18.5px and 24px.

Please let me know if there's the need to open a new issue, thanks!

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.

4 participants