Skip to content

Commit

Permalink
perf: Don't render Checkbox icon when unchecked (#26248)
Browse files Browse the repository at this point in the history
Don't render the checkmark at all when unchecked, and remove the universal selector rule in CSS.
  • Loading branch information
behowell committed Jan 9, 2023
1 parent e361553 commit 204f1c4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 54 deletions.
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: Don't render Checkbox icon when unchecked",
"packageName": "@fluentui/react-checkbox",
"email": "behowell@microsoft.com",
"dependentChangeType": "patch"
}
Expand Up @@ -41,22 +41,7 @@ exports[`Checkbox renders a default state 1`] = `
<div
aria-hidden="true"
class="fui-Checkbox__indicator"
>
<svg
aria-hidden="true"
class=""
fill="currentColor"
height="12"
viewBox="0 0 12 12"
width="12"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.76 3.2c.3.29.32.76.04 1.06l-4.25 4.5a.75.75 0 01-1.08.02L2.22 6.53a.75.75 0 011.06-1.06l1.7 1.7L8.7 3.24a.75.75 0 011.06-.04z"
fill="currentColor"
/>
</svg>
</div>
/>
</span>
</div>
`;
Expand Down Expand Up @@ -153,22 +138,7 @@ exports[`Checkbox renders with a label 1`] = `
<div
aria-hidden="true"
class="fui-Checkbox__indicator"
>
<svg
aria-hidden="true"
class=""
fill="currentColor"
height="12"
viewBox="0 0 12 12"
width="12"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.76 3.2c.3.29.32.76.04 1.06l-4.25 4.5a.75.75 0 01-1.08.02L2.22 6.53a.75.75 0 011.06-1.06l1.7 1.7L8.7 3.24a.75.75 0 011.06-.04z"
fill="currentColor"
/>
</svg>
</div>
/>
<label
class="fui-Label fui-Checkbox__label"
for="checkbox-1"
Expand Down
Expand Up @@ -53,7 +53,7 @@ export const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLIn
} else {
checkmarkIcon = size === 'large' ? <Square16Filled /> : <Square12Filled />;
}
} else {
} else if (checked) {
checkmarkIcon = size === 'large' ? <Checkmark16Filled /> : <Checkmark12Filled />;
}

Expand Down
Expand Up @@ -33,11 +33,6 @@ const useInputBaseClassName = makeResetStyles({
// This is done so that clicking on that "empty space" still toggles the checkbox.
width: `calc(${indicatorSizeMedium} + 2 * ${tokens.spacingHorizontalS})`,

// When unchecked, hide the the checkmark icon (child of the indicator slot)
[`:not(:checked):not(:indeterminate) ~ .${checkboxClassNames.indicator} > *`]: {
opacity: 0,
},

// Colors for the unchecked state
':enabled:not(:checked):not(:indeterminate)': {
[`& ~ .${checkboxClassNames.label}`]: {
Expand Down
Expand Up @@ -16,22 +16,7 @@ exports[`TableSelectionCell renders a default state 1`] = `
<div
aria-hidden="true"
class="fui-Checkbox__indicator"
>
<svg
aria-hidden="true"
class=""
fill="currentColor"
height="12"
viewBox="0 0 12 12"
width="12"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.76 3.2c.3.29.32.76.04 1.06l-4.25 4.5a.75.75 0 01-1.08.02L2.22 6.53a.75.75 0 011.06-1.06l1.7 1.7L8.7 3.24a.75.75 0 011.06-.04z"
fill="currentColor"
/>
</svg>
</div>
/>
</span>
</td>
</tr>
Expand Down

0 comments on commit 204f1c4

Please sign in to comment.