Skip to content

Commit

Permalink
fix(Checkbox): center checkbox icon (#1821)
Browse files Browse the repository at this point in the history
Co-authored-by: Chitangchin <[email protected]>
  • Loading branch information
PlanckConst and chitangchin authored Nov 27, 2024
1 parent 3d7125f commit 0693ce9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .changeset/purple-rivers-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
'@strapi/design-system': patch
---

fix: Checkbox Item Not Centered

Added justify-content: center and align-items: center to Checkbox Indicator component

Original:

const CheckboxIndicator = styled(Checkbox.Indicator)` width: 100%;
height: 100%;
cursor: pointer;`;

Updated:

const CheckboxIndicator = styled(Checkbox.Indicator)`

- display: inline-flex;
- pointer-events: auto !important;
width: 100%;
height: 100%;
cursor: pointer;
- justify-content: center;
- align-items: center;
`;

Refactored inline styling and added it to checkbox indicator stype component

Original:

<CheckboxIndicator style={{ display: 'inline-flex', pointerEvents: 'auto'}} forceMount>

Updated:

<CheckboxIndicator forceMount>
6 changes: 5 additions & 1 deletion packages/design-system/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const CheckboxEl = React.forwardRef<CheckboxElement, CheckboxElProps>(

return (
<CheckboxRoot ref={composedRefs} checked={checked} onCheckedChange={setChecked} {...props}>
<CheckboxIndicator style={{ display: 'inline-flex', pointerEvents: 'auto' }} forceMount>
<CheckboxIndicator forceMount>
{checked === true ? <CheckIcon width="1.6rem" fill="neutral0" /> : null}
{checked === 'indeterminate' ? <Minus fill="neutral0" /> : null}
</CheckboxIndicator>
Expand Down Expand Up @@ -101,9 +101,13 @@ const CheckboxRoot = styled(Checkbox.Root)`
`;

const CheckboxIndicator = styled(Checkbox.Indicator)`
display: inline-flex;
pointer-events: auto !important;
width: 100%;
height: 100%;
cursor: pointer;
justify-content: center;
align-items: center;
`;

/* -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 0693ce9

Please sign in to comment.