-
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
CustomSelectControl V2: allow wrapping item hint to new line #62848
Conversation
1430782
to
57b3613
Compare
<Styled.ItemHintWrapper> | ||
<Styled.ItemHintContent>{ name }</Styled.ItemHintContent> | ||
<Styled.ItemHint className="components-custom-select-control__item-hint"> | ||
{ __experimentalHint } | ||
</Styled.ExperimentalHintItem> | ||
</Styled.WithHintWrapper> | ||
</Styled.ItemHint> | ||
</Styled.ItemHintWrapper> |
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.
Notable changes:
- Converted the
span
that wraps{ name }
to a styled component to add somepadding-inline-end
, ensuring a bit of spacing between the item content and the hint - Renamed the remaining styled components to have a more coherent name structure
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 name ItemHintContent
feels wrong to me, since it wraps the item content and not the hint content.
Also, did we consider adding a gap
instead of padding?
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 name ItemHintContent feels wrong to me, since it wraps the item content and not the hint content.
I wasn't happy with it either but I've been struggling with good naming — pushed a new attempt, hopefully things are more clear!
Also, did we consider adding a gap instead of padding?
I initially considered using gap
, but then realised that I needed different gaps based on whether the hint was rendering on the same line, or wrapping on the line line — and therefore I opted for padding and margin.
But after your question, I looked into it again, and discovered and row-gap
and column-gap
apply to flexbox too, and so I refactored accordingly — thank you for the suggestion!
'components-custom-select-control__item', | ||
!! __experimentalHint && 'has-hint', |
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.
Consumers of the V1 component expect these classnames and use them to style specifically the hint
part (try searching for .has-hint
in the codebase).
I'll see if I can bring in more changes to the hint so that these overrides are not necessary in the editor, but it's probably sensible to leave those classnames there, at least for the legacy adapter.
Flaky tests detected in dfcedd9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9674369680
|
align-items: center; | ||
flex-wrap: wrap; |
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.
Added these two rules to allow hint to wrap, and to preserve vertical centering even after adding a smaller line-height
for the hint
color: ${ COLORS.theme.gray[ 600 ] }; | ||
text-align: initial; | ||
line-height: 1.4; | ||
padding-inline-end: ${ space( 1 ) }; |
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.
Using padding here to better match legacy behavior. Also, the V1 styles are loaded in the editor, if we use the legacy components-custom-select-control__item
we will get those styles applied to the V2 as well 😅 Without changing margin-inline-end
to padding-inline-end
, the hint would get both a margin and a padding applied
// '.components-custom-select-control__item-hint' class | ||
${ SelectItem } && { | ||
color: ${ COLORS.theme.gray[ 600 ] }; | ||
text-align: initial; |
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.
Since we use flexbox to push the hint to the right, text-align
isn't necessary per se, but since V1 styles are "leaking" to this implementation too, we need to reset the value to initial
. This allows the hint text to be correctly aligned both when it's on the same line as the item's content, and when it wraps to its own independent line.
${ SelectItem } && { | ||
color: ${ COLORS.theme.gray[ 600 ] }; | ||
text-align: initial; | ||
line-height: ${ CONFIG.fontLineHeightBase }; |
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 hint needs to use the default line-height
value (and not the one of the option item), since it could render multi-line text. When rendered on the same line as the option item text, vertical alignment is still guaranteed by flexbox.
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. |
a45f844
to
9a60dab
Compare
<Styled.ItemHintWrapper> | ||
<Styled.ItemHintContent>{ name }</Styled.ItemHintContent> | ||
<Styled.ItemHint className="components-custom-select-control__item-hint"> | ||
{ __experimentalHint } | ||
</Styled.ExperimentalHintItem> | ||
</Styled.WithHintWrapper> | ||
</Styled.ItemHint> | ||
</Styled.ItemHintWrapper> |
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 name ItemHintContent
feels wrong to me, since it wraps the item content and not the hint content.
Also, did we consider adding a gap
instead of padding?
// Necessary to override V1 styles passed via the legacy | ||
// '.components-custom-select-control__item' class |
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.
Do you mean these styles? I guess we can remove the &&
hack right after we replace the v1 with v2 legacy, but also we might just want to remove the v1 stylesheet import while we test v2 legacy styling because there are probably other weird interference as well.
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.
Do you mean these styles?
Yup!
I guess we can remove the && hack right after we replace the v1 with v2 legacy
That's what I had in mind as well — I've added an extra item in the tracking issue so that we don't forget
we might just want to remove the v1 stylesheet import while we test v2 legacy styling because there are probably other weird interference as well.
That's a good point. Let's schedule some testing with/without importing V1 styles once all current style fixes are merged — added that to the tracking issues too.
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.
Another way I just thought of is to comment out the legacy classnames we're passing in legacy-component/index.tsx
until we're ready to remove the v1 implementation and styles.
Your call, but that might be simpler than cleaning up the small hacks we're adding in this PR.
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.
Clever! I went ahead and followed your suggestion — seems to work well!
When gradually swapping to legacy V2 we'll probably have to enable them (at least while testing) so that overrides like this one can take effect — unless we ignore those overrides and have the component behave "vanilla".
9a60dab
to
21950ec
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.
Looks good and works well, though this might be an alternative to merging in some of the temporary hacks.
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.
Looking good and testing well for me 👍
packages/components/src/custom-select-control-v2/legacy-component/index.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/custom-select-control-v2/legacy-component/index.tsx
Outdated
Show resolved
Hide resolved
21950ec
to
92e358b
Compare
92e358b
to
48f1a0d
Compare
…ss#62848) * Wrap item hint when it doesn't fit * Set more legacy classnames * Use padding instead of margin * CHANGELOG * Move hint styles to bottom of file, add more specificity to override v1 styles * Better defaults for V2 legacy styles * Use line-height variable * Add block margin to hint for better spacing when collapsed * More renaming * Today I (re-)learned row and column gap * Comment out legacy classnames, remove && specificity hack in styles * Swap row-gap with margin-block on the hint for better vertical spacing when on separate rows --- Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
What?
Part of #55023
Improve how inidivual item hints are rendered for the
CustomSelectControl
V2 legacy adapter, by allowing the hint to wrap below the item's content, instead of being forced on the same line.Why?
Even if the previous layout is how the V1 component behaves, it does not produce good-looking UI when the select popover is narrow. And it often overridden in the editor via custom style overrides anyway, which is bad.
These changes basically bring to the component the overrides that were applied in the editor.
How?
Using flexbox to allow the hint to break the line and render below the item's content.
Testing Instructions
Storybook
Click to show diff
hint.-storybook.-.cscv1.mp4
hint.-storybook.-.cscv2.before.mp4
hint.-storybook.-.cscv2.after.mp4
Editor
First, apply the following patch
Click to show diff
DateFormat picker
trunk
hint.-.date.format.-.cscv1.mp4
hint.-.date.format.-.cscv2.before.mp4
hint.-.date.format.-.cscv2.after.mp4
Position picker
trunk
hint.-.position.-.cscv1.mp4
hint.-.position.-.cscv2.before.mp4
hint.-.position.-.cscv2.after.mp4
Known bugs
There are several known layout bugs related to
CustomSelectControlV2
— most of them are addressed in separate PRs (see #55023). When reviewing this PR, please focus only on the layout of option item hints.