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

CustomSelectControlV2: fix item styles #62825

Merged
merged 7 commits into from
Jul 1, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Jun 25, 2024

What?

Part of #55023

Fix items (options) styles of CustomSelectControlV2 component

Why?

  • To fix visual bugs
  • To match more closely look of V1 component
  • To add quality of life improvements

How?

  • Update V2 items in order to match the same line height of the V1 version
  • Add disabled styles
  • Added user-select: none to trigger button and option items
  • Added scroll-margin to improve scroll experience when selecting items that are out of view in the popover

Testing Instructions

  • Compare V1 and V2 (legacy) of CustomSelectControl, make sure that the items in the select popover now render with the same line height (28px).
  • Try to select with the cursor the text of the items in the select popover — V2 should prevent text selection
V1 V2 before (trunk) V2 after (this PR)
Screenshot 2024-06-25 at 13 13 47 Screenshot 2024-06-25 at 13 14 27 Screenshot 2024-06-25 at 13 23 21

@ciampo ciampo self-assigned this Jun 25, 2024
@ciampo ciampo added [Package] Components /packages/components [Type] Bug An existing feature does not function as intended labels Jun 25, 2024
@ciampo ciampo marked this pull request as ready for review June 25, 2024 11:26
@ciampo ciampo requested a review from ajitbohra as a code owner June 25, 2024 11:26
@ciampo ciampo requested a review from a team June 25, 2024 11:26
Copy link

github-actions bot commented Jun 25, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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
Copy link
Contributor Author

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.

Copy link
Member

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...

Copy link
Contributor Author

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.

Copy link
Member

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.

@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-style branch 3 times, most recently from 6ecc280 to 6235497 Compare June 27, 2024 08:52
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 } );
Copy link
Member

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".)

Copy link
Member

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.

Copy link
Contributor Author

@ciampo ciampo Jul 1, 2024

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

Copy link
Member

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.

Copy link
Contributor Author

@ciampo ciampo Jul 1, 2024

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Comment on lines 143 to 144
&[aria-disabled='true'] {
opacity: 0.5;
}
Copy link
Member

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.

/**
* 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?

Copy link
Contributor Author

@ciampo ciampo Jul 1, 2024

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

packages/components/CHANGELOG.md Outdated Show resolved Hide resolved
@@ -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
Copy link
Member

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 } );
Copy link
Member

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.

@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-style branch from 6235497 to 37ee79c Compare July 1, 2024 12:34
@ciampo ciampo requested review from mirka and tyxla July 1, 2024 12:36
Copy link
Member

@tyxla tyxla left a 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! :shipit:

@@ -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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ciampo ciampo enabled auto-merge (squash) July 1, 2024 16:18
@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-style branch from 37ee79c to ee95320 Compare July 1, 2024 16:26
@ciampo ciampo merged commit 12518a0 into trunk Jul 1, 2024
62 checks passed
@ciampo ciampo deleted the fix/custom-select-control-v2-item-style branch July 1, 2024 17:01
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 1, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
* 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 <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants