Add validation check for type scale accessibility #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background: If you're not careful, when using fluid typography it's possible to end up violating the WCAG SC 1.4.4 accessibility rule (about zooming text).
Fortunately it's possible to do some math to ensure that the rule is not violated. More details here:
https://www.smashingmagazine.com/2023/11/addressing-accessibility-concerns-fluid-type/
I'm not a math whiz myself, but fortunately someone already implemented the validation discussed in the article, so I was able to adapt the code from this existing repo:
https://github.com/barvian/fluid-tailwind/blob/f85f1ae5a50ec1a37f99418d6d087a3a2e783e1b/packages/fluid-tailwind/src/util/expr.ts#L116
I decided to make it an error by default and also to still show it as a warning if you set
typeScale.validateAccessibilityto false, but I could of course change the PR if different behavior is desired.