Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try: Reduce checkbox size in data views #60475

Merged
merged 11 commits into from
Apr 16, 2024
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

- `ProgressBar`: Fix CSS variable with invalid value ([#60576](https://github.com/WordPress/gutenberg/pull/60576)).

### Internal

- `CheckboxControl`: Streamline size styles ([#60475](https://github.com/WordPress/gutenberg/pull/60475)).

## 27.3.0 (2024-04-03)

### Bug Fix
Expand Down
45 changes: 21 additions & 24 deletions packages/components/src/checkbox-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
$checkbox-input-size: 20px;
$checkbox-input-size-sm: 24px; // Width & height for small viewports.
.components-checkbox-control {
--checkbox-input-size: 24px; // Width & height for small viewports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the size for small viewports private for now, since we don't need to override it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that. I discussed this with @DaniGuardiola and decided that we shouldn't be exposing an official-looking CSS var for this sizing experiment. Made some changes on how we override it. On the whole though, this style refactor should allow more of a safer override, although not "officially" sanctioned.

@include break-small() {
--checkbox-input-size: var(--wp-components-checkbox-control-size, 20px);
}
}

.components-checkbox-control__input[type="checkbox"] {
@include checkbox-control;
Expand All @@ -14,13 +19,8 @@ $checkbox-input-size-sm: 24px; // Width & height for small viewports.
padding: 0 !important;
text-align: center;
vertical-align: top;
width: $checkbox-input-size-sm;
height: $checkbox-input-size-sm;

@include break-small() {
height: $checkbox-input-size;
width: $checkbox-input-size;
}
width: var(--checkbox-input-size);
aspect-ratio: 1;

appearance: none;
transition: 0.1s border-color ease-in-out;
Expand Down Expand Up @@ -51,29 +51,26 @@ $checkbox-input-size-sm: 24px; // Width & height for small viewports.
display: inline-block;
margin-right: 12px;
vertical-align: middle;
width: $checkbox-input-size-sm;
height: $checkbox-input-size-sm;

@include break-small() {
width: $checkbox-input-size;
height: $checkbox-input-size;
}
width: var(--checkbox-input-size);
aspect-ratio: 1;
}

svg.components-checkbox-control__checked,
svg.components-checkbox-control__indeterminate {
--checkmark-size: var(--checkbox-input-size);

fill: $white;
cursor: pointer;
position: absolute;
left: 0;
top: 0;
width: $button-size-small;
height: $button-size-small;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: var(--checkmark-size);
height: var(--checkmark-size);
user-select: none;
pointer-events: none;

@include break-small() {
left: -2px;
top: -2px;
--checkmark-size: calc(var(--checkbox-input-size) + 4px);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in trunk, the icon size is 24px regardless of whether the input is 20px or 24px. I left it that way, but we could simplify the code (and possibly correct the visual incongruence) if that was unintended.

user-select: none;
pointer-events: none;
}
29 changes: 15 additions & 14 deletions packages/dataviews/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
overflow: auto;
box-sizing: border-box;
scroll-padding-bottom: $grid-unit-80;

--wp-components-checkbox-control-size: 16px;
}

.dataviews-filters__view-actions {
Expand Down Expand Up @@ -92,10 +94,6 @@
&.dataviews-view-table__checkbox-column {
padding-right: 0;
}

.components-checkbox-control__input-container {
margin: $grid-unit-05;
}
}
tr {
border-bottom: 1px solid $gray-100;
Expand Down Expand Up @@ -532,16 +530,19 @@
justify-content: center;
}

.dataviews-view-table-selection-checkbox label {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
.dataviews-view-table-selection-checkbox {
line-height: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this the checkbox wrapper renders at 18.58px tall which throws off the horizontal alignment with the smaller checkboxes.

label {
position: absolute;
Comment on lines +539 to +540
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the pain here, we do eventually want to make this kind of checkbox layout possible without hacks! I'll bump the priority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameskoster I was thinking about this in the context of #60799 and realized it was already possible. Quick fix proposed in #60835.

width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
}

.dataviews-filters__custom-menu-radio-item-prefix {
Expand Down
6 changes: 2 additions & 4 deletions packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ function TableRow( {
<td
className="dataviews-view-table__checkbox-column"
style={ {
width: 20,
minWidth: 20,
width: '1%',
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
} }
>
<div className="dataviews-view-table__cell-content-wrapper">
Expand Down Expand Up @@ -426,8 +425,7 @@ function ViewTable( {
<th
className="dataviews-view-table__checkbox-column"
style={ {
width: 20,
minWidth: 20,
width: '1%',
} }
data-field-id="selection"
scope="col"
Expand Down
Loading