Skip to content

Commit

Permalink
Add some error handling to sufficient-contrast helper
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Aug 1, 2023
1 parent afcb56b commit e4c1f45
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/helpers/sufficient-contrast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export function sufficientContrast(
): boolean {
const standard = useAAA ? wcagAAA : wcagAA;
const threshold = largeText ? standard.largeText : standard.normalText;

if (!backgroundColor || !foregroundColor) {
return false;
}

let bg = backgroundColor.replace('#', '');
let fg = foregroundColor.replace('#', '');
bg = bg.length === 3 ? threeDigitHexToSixDigit(bg) : bg;
Expand Down

0 comments on commit e4c1f45

Please sign in to comment.