Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Checkbox Component Styling Fix (#5164)
Browse files Browse the repository at this point in the history
* Wrap label in div to prevent clickable area growing too large

* Prevent pointer events on svg

* Double gap in editor
  • Loading branch information
mikejolley committed Nov 22, 2021
1 parent e8c4fa1 commit 28e83ee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
Expand Up @@ -12,10 +12,6 @@
}
}

.wc-block-components-checkbox {
margin-right: $gap;
}

.wc-block-checkout__terms_notice .components-notice__action {
margin-left: 0;
}
Expand Down
51 changes: 26 additions & 25 deletions packages/checkout/components/checkbox-control/index.tsx
Expand Up @@ -35,39 +35,40 @@ const CheckboxControl = ( {
const checkboxId = id || `checkbox-control-${ instanceId }`;

return (
<label
<div
className={ classNames(
'wc-block-components-checkbox',
{
'has-error': hasError,
},
className
) }
htmlFor={ checkboxId }
>
<input
id={ checkboxId }
className="wc-block-components-checkbox__input"
type="checkbox"
onChange={ ( event ) => onChange( event.target.checked ) }
aria-invalid={ hasError === true }
{ ...rest }
/>
<svg
className="wc-block-components-checkbox__mark"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 20"
>
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
</svg>
{ label && (
<span className="wc-block-components-checkbox__label">
{ label }
</span>
) }
{ children }
</label>
<label htmlFor={ checkboxId }>
<input
id={ checkboxId }
className="wc-block-components-checkbox__input"
type="checkbox"
onChange={ ( event ) => onChange( event.target.checked ) }
aria-invalid={ hasError === true }
{ ...rest }
/>
<svg
className="wc-block-components-checkbox__mark"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 20"
>
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
</svg>
{ label && (
<span className="wc-block-components-checkbox__label">
{ label }
</span>
) }
{ children }
</label>
</div>
);
};

Expand Down
12 changes: 8 additions & 4 deletions packages/checkout/components/checkbox-control/style.scss
@@ -1,10 +1,13 @@
.wc-block-components-checkbox {
@include reset-typography();
align-items: flex-start;
display: flex;
position: relative;
margin-top: em($gap-large);

label {
align-items: flex-start;
display: flex;
position: relative;
}

.wc-block-components-checkbox__input[type="checkbox"] {
font-size: 1em;
appearance: none;
Expand All @@ -14,6 +17,7 @@
height: em(24px);
width: em(24px);
margin: 0;
margin-right: $gap;
min-height: 24px;
min-width: 24px;
overflow: hidden;
Expand Down Expand Up @@ -83,6 +87,7 @@
margin-top: em(1px);
width: em(18px);
height: em(18px);
pointer-events: none;

.has-dark-controls & {
fill: #fff;
Expand All @@ -91,7 +96,6 @@

> span,
.wc-block-components-checkbox__label {
padding-left: $gap;
vertical-align: middle;
line-height: em(24px);
}
Expand Down

0 comments on commit 28e83ee

Please sign in to comment.