Color converter: the contrast ratio shows `4.50 : 1` while Normal AA says FAIL
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
In the color converter's WCAG Contrast Checker, set Text / Foreground to #FFFFFF and Surface / Background to #EB1717. The ratio reads 4.50 : 1, and the Normal AA badge (which needs 4.5:1) says FAIL.
Both come from the same number, 4.499327326513352. The FAIL is right and the display isn't: formatRatio (app/(tools)/color-converter/ColorConverterClient.tsx, lines 33 to 35) uses toFixed(2), which rounds it up to 4.50. W3C's Understanding SC 1.4.3 says the computed ratio should not be rounded ("4.499:1 would not meet the 4.5:1 threshold"), so a checker that shows 4.50 next to FAIL leaves people unsure which of the two to believe.
It happens at the other thresholds too:
| Text | Background | Ratio | Shown now | Expected | Threshold it misses |
|---|---|---|---|---|---|
#FFFFFF |
#EB1717 |
4.499327326513352 | 4.50 : 1 |
4.49 : 1 |
4.5:1 (Normal AA, Large AAA) |
#EE0707 |
#FFFFFF |
4.497858855042646 | 4.50 : 1 |
4.49 : 1 |
4.5:1 (Normal AA, Large AAA) |
#575757 |
#CCCCCC |
4.499612814225531 | 4.50 : 1 |
4.49 : 1 |
4.5:1 (Normal AA, Large AAA) |
#959595 |
#FFFFFF |
2.9953461357088114 | 3.00 : 1 |
2.99 : 1 |
3:1 (Large AA) |
#176363 |
#FFFFFF |
6.996878801802648 | 7.00 : 1 |
6.99 : 1 |
7:1 (Normal AAA) |
The badges come from wcagRating (lib/color-utils.ts, line 473), which compares the unrounded ratio, so they're already correct.
What to do
- Truncate the shown ratio to two decimals instead of rounding it, so it never shows more contrast than the colors have: 4.4993 shows
4.49, and exactly 4.5 still shows4.50. - Watch out for floating point:
Math.floor(4.56 * 100) / 100is4.55, because4.56 * 100is455.99999999999994. A ratio of exactly 4.56 should still show4.56. - Move the helper to
lib/color-utils.ts(for exampleformatContrastRatio) so it can have unit tests, and use it at line 601. - The default pair (
#FFFFFFon#0A0B0F, 19.668948449427404) will show19.66instead of19.67. That's expected. - Leave
wcagRatingand the colored bar (lines 609 to 613) as they are.
Where to look
app/(tools)/color-converter/ColorConverterClient.tsx:formatRatio(lines 33 to 35) and where it's shown (line 601)lib/color-utils.ts:contrastRatio(line 444) andwcagRating(line 473)lib/__tests__/color-utils.test.ts: thecontrastRatiotests (line 142) and thewcagRatingtests (line 195)
Acceptance criteria
- Every row in the table shows the expected ratio, and the PASS/FAIL badges don't change
- Ratios of 21, 1, 4.5 and 4.56 show
21.00,1.00,4.50and4.56 - Unit tests for the helper with the table rows and these values
-
npm run lint,npm run testandnpm run buildpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #235 in the description.
- Ngôn ngữ chính
- TypeScript
- Star
- 1
- Fork
- 9
- Merge trung bình
- 7 giờ 34 phút
- Pull request đã merge (30 ngày)
- 146
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codercops/toolbelt
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Cron explainer says "on weekdays" for `0 0 1-31 * 1-5`, but the next runs include weekendsCó thể đã có người làm @Saifjafri212213 đã nhận hôm nay. Đang mởbug hacktoberfest help wanted
codercops/toolbelt#329 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
UUID generator's v7 batch comes out in random order instead of time orderCó thể đã có người làm @omisha123 đã nhận hôm nay. Đang mởbug good first issue hacktoberfest
codercops/toolbelt#316 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Invoice generator shows a subtotal of -$0.00 when the line items cancel outCó thể đã có người làm @shresthgoel77-png đã nhận hôm nay. Đang mởbug good first issue hacktoberfest
codercops/toolbelt#315 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON formatter's "Did you mean" hint reads inside strings, so a missing comma near a URL says to remove commentsCó thể đã có người làm @kachamsiddarth đã nhận hôm nay. Đang mởbug good first issue hacktoberfest
codercops/toolbelt#314 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của codercops/toolbelt
Issue tương tự
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
openclaw/openclaw#182077 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
aikido high security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dequelabs/axe-linter-action#161 ·
-
[Feature Request] Update the DimCode agent icon to the 45:32 brand markCó thể đã có người làm @eric8810 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: 建议导入源后,自动切换到新导入的源Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
lyswhut/lx-music-desktop#3026 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
abhigyanpatwari/GitNexus#3704 ·
Maintainer thường phản hồi trong vòng 1 ngày