Skip to content

Commit

Permalink
Fix: Contrast checker: Consider fontSize large when size >= 24px inst…
Browse files Browse the repository at this point in the history
…ead of >= 18px
  • Loading branch information
jorgefilipecosta committed Aug 23, 2018
1 parent e959064 commit d5021a2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class ButtonEdit extends Component {
>
<ContrastChecker
{ ...{
isLargeText: true,
// Text is considered large if font size is greater or equal to 18pt or 24px,
// currently that's not the case for button.
isLargeText: false,
textColor: textColor.color,
backgroundColor: backgroundColor.color,
fallbackBackgroundColor,
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/contrast-checker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ContrastChecker( {
backgroundColor,
fallbackBackgroundColor,
fallbackTextColor,
fontSize,
fontSize, // font size value in pixels
isLargeText,
textColor,
} ) {
Expand All @@ -27,7 +27,7 @@ function ContrastChecker( {
if ( hasTransparency || tinycolor.isReadable(
tinyBackgroundColor,
tinyTextColor,
{ level: 'AA', size: ( isLargeText || ( isLargeText !== false && fontSize >= 18 ) ? 'large' : 'small' ) }
{ level: 'AA', size: ( isLargeText || ( isLargeText !== false && fontSize >= 24 ) ? 'large' : 'small' ) }
) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ exports[`ContrastChecker should render messages when the textColor is valid, but
exports[`ContrastChecker should take into consideration the font size passed 1`] = `
<ContrastChecker
backgroundColor="#C44B4B"
fontSize={17}
fontSize={23}
textColor="#000000"
>
<div
Expand Down Expand Up @@ -141,7 +141,7 @@ exports[`ContrastChecker should take into consideration wherever text is large o
exports[`ContrastChecker should use isLargeText to make decisions if both isLargeText and fontSize props are passed 1`] = `
<ContrastChecker
backgroundColor="#C44B4B"
fontSize={18}
fontSize={24}
isLargeText={false}
textColor="#000000"
>
Expand Down
8 changes: 4 additions & 4 deletions packages/editor/src/components/contrast-checker/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe( 'ContrastChecker', () => {
<ContrastChecker
backgroundColor="#C44B4B"
textColor="#000000"
fontSize={ 17 }
fontSize={ 23 }
/>
);

Expand All @@ -125,7 +125,7 @@ describe( 'ContrastChecker', () => {
<ContrastChecker
backgroundColor="#C44B4B"
textColor="#000000"
fontSize={ 18 }
fontSize={ 24 }
/>
);

Expand All @@ -137,7 +137,7 @@ describe( 'ContrastChecker', () => {
<ContrastChecker
backgroundColor="#C44B4B"
textColor="#000000"
fontSize={ 17 }
fontSize={ 23 }
isLargeText={ true }
/>
);
Expand All @@ -148,7 +148,7 @@ describe( 'ContrastChecker', () => {
<ContrastChecker
backgroundColor="#C44B4B"
textColor="#000000"
fontSize={ 18 }
fontSize={ 24 }
isLargeText={ false }
/>
);
Expand Down

0 comments on commit d5021a2

Please sign in to comment.