-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
CustomSelectControlV2: fix item styles #62825
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -108,7 +108,14 @@ export const SelectItem = styled( Ariakit.SelectItem )` | |||
justify-content: space-between; | |||
padding: ${ ITEM_PADDING }; | |||
font-size: ${ CONFIG.fontSize }; | |||
line-height: 2.15rem; // TODO: Remove this in default but keep for back-compat in legacy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match 28px, the line height value should have been 2.15
(without the rem
unit). I felt like a more explicit calc
syntax would help to understand the reason for an arbitrary number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's curious where the 2.15 came from originally...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the ratio of the line height (28px) to the font size (13px)
Also, since 28 / 13 = 2.15384615
, another consequence of using 2.15
is that the resulting line height wouldn't be exactly 28px (as per design), but slightly less because of the lower decimal precision.
In short: I prefer to let the browser (or sass) do the calculation, and if not possible, to state the line-height
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since 28 / 13 = 2.15384615, another consequence of using 2.15 is that the resulting line height wouldn't be exactly 28px (as per design), but slightly less because of the lower decimal precision.
Which also makes me question if 28/13 was the intent. But yes, having a clear calc there makes things much clearer.
6ecc280
to
6235497
Compare
line-height: 2.15rem; // TODO: Remove this in default but keep for back-compat in legacy | ||
// Legacy line height is 28px. | ||
// TODO: reassess for non-legacy v2 | ||
line-height: calc( 28px / ${ CONFIG.fontSize } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently this calc
doesn't work 😕 ("For /
, the right operand must be unitless".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if we wrap CONFIG.fontSize()
in a stringToNumber()
? I appreciate the clarity that the explicit calc adds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes less is more — we can also just remove the ${ CONFIG.fontSize }
part, and simply state 28px
— pushed in 9a5d26f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But these 2 aren't the same, are they:
font-size: 13px;
line-height: 2.15384615
and:
font-size: 13px
line-height: 28px
because if someone overrides only the font-size
, the line-height
will behave differently - considering the new font-size in the first example, and ignoring it in the second one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To adhere more closely to legacy behavior, It's actually better to keep the hardcoded 28px
as V1 does, exactly for the reason you state. For example, in the default Storybook example of CustomSelectControl
each select item has a custom font-size
, but the line-height is supposed to stay the same instead of scaling up/down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line-height is supposed to stay the same instead of scaling up/down.
Interesting - is this always the case? What if I have font-size 56px, won't it be ugly with line-height of 28px?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can review that when assessing what line-height
to adopt for the V2 — keeping it as hardcoded 28px
is probably the safest choice while swapping the V1 implementation
&[aria-disabled='true'] { | ||
opacity: 0.5; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually omitted the disabled styles on purpose, because the item styles are fully customizable and the appropriate disabled style will vary. For example, adding a disabled
to the "Purple" item in the Default story doesn't result in an understandable visual.
gutenberg/packages/components/src/custom-select-control-v2/types.ts
Lines 196 to 202 in 9a331f1
/** | |
* If true, the item will be disabled. | |
* | |
* You will need to add your own styles (e.g. reduced opacity) to visually show that they are disabled. | |
* @default false | |
*/ | |
disabled?: boolean; |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You raise a good point — although I also think that the component should offer some good defaults.
Testing a middle ground in 37ee79c , using cursor: not-allowed
as a more un-opinionated way to apply default disabled item styles.
Let me know if you still think this is too much
@@ -108,7 +108,14 @@ export const SelectItem = styled( Ariakit.SelectItem )` | |||
justify-content: space-between; | |||
padding: ${ ITEM_PADDING }; | |||
font-size: ${ CONFIG.fontSize }; | |||
line-height: 2.15rem; // TODO: Remove this in default but keep for back-compat in legacy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's curious where the 2.15 came from originally...
line-height: 2.15rem; // TODO: Remove this in default but keep for back-compat in legacy | ||
// Legacy line height is 28px. | ||
// TODO: reassess for non-legacy v2 | ||
line-height: calc( 28px / ${ CONFIG.fontSize } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if we wrap CONFIG.fontSize()
in a stringToNumber()
? I appreciate the clarity that the explicit calc adds.
6235497
to
37ee79c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor suggestion, but other than that, this looks good to me. Thanks!
@@ -133,7 +134,15 @@ export const SelectItem = styled( Ariakit.SelectItem )` | |||
justify-content: space-between; | |||
padding: ${ ITEM_PADDING }; | |||
font-size: ${ CONFIG.fontSize }; | |||
line-height: 2.15rem; // TODO: Remove this in default but keep for back-compat in legacy | |||
// TODO: reassess line-height for non-legacy v2 | |||
line-height: 28px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer 2.15384615
and adding a comment about how it's calculated, because that way we'll keep the flexibility/relativity in case someone modifies only the font-size
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #62825 (comment)
37ee79c
to
ee95320
Compare
* Fix line height * Add disabled styles * CHANGELOG * Prevent user selection for items text * Apply more tweaks * Remove extra changelog entry * Simplify line-height styles * Less opinionated item disabled styles --- Co-authored-by: ciampo <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: tyxla <[email protected]>
What?
Part of #55023
Fix items (options) styles of
CustomSelectControlV2
componentWhy?
How?
disabled
stylesuser-select: none
to trigger button and option itemsscroll-margin
to improve scroll experience when selecting items that are out of view in the popoverTesting Instructions
CustomSelectControl
, make sure that the items in the select popover now render with the same line height (28px).