GoogleChrome / accessibility-developer-tools

This is a library of accessibility-related testing and utility code.
Apache License 2.0
2.28k stars 362 forks source link

axs.utils.isLargeFont returns incorrect values with non-integer fonts #345

Open timmhayes opened 7 years ago

timmhayes commented 7 years ago

The axs.utils.isLargeFont() function fails on font sizes with float values.

I saw this first when testing a value of 10pt, which gets a computed value of 13.3333px in Chrome. The current function evaluates this incorrectly as a large font with a value of "3333px". Or conversely, a font value of 30.1px evaluates incorrectly as a small font with a value of "1px"

See a working example here: http://jsbin.com/cehiben/edit?html,output

A small chunk of testable code extracted from isLargeFont() shows the issue:

 var fontSize = "13.3333px"
 var matches = fontSize.match(/(\d+)px/);
 if (matches) {
   var fontSizePx = parseInt(matches[1], 10); // parses as 3333, not 13
   console.log(fontSizePx)
 }

I'll submit a pull request with a suggested fix.

This is also causing a failure in Khan Academy's tota11y toolkit.