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: Handle long strings in selected value #62198

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented May 31, 2024

Part of #55023

What?

Correctly truncate and style long strings in the currently selected value in CustomSelectControlV2.

Why?

Long strings were not styled correctly.

Before

Long strings look wrong

Testing Instructions

Compare the "With Long Labels" stories between CustomSelectControl (v1) and CustomSelectControlV2 Legacy. All size variants should look correct.

Note

You may notice that the LABEL is shifted down 1px in the v1. I looked into it and v1 is actually wrong in this case, so let's ignore. (FWIW, it will look correct in wp-admin due to a style in the forms.css stylesheet.)

Screenshots or screencast

v1 v2 Default & Legacy
Long labels long v1 long v2 legacy
With hints hint v1 hint v2 legacy
@mirka mirka added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels May 31, 2024
@mirka mirka self-assigned this May 31, 2024
@mirka mirka requested a review from ajitbohra as a code owner May 31, 2024 20:12
Copy link

github-actions bot commented May 31, 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: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: fullofcaffeine <fullofcaffeine@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@mirka mirka force-pushed the custom-select-v2-long-strings branch from f3b0f8d to a68fce4 Compare May 31, 2024 20:14
@@ -74,7 +74,7 @@ const CustomSelectButton = ( {
// move selection rather than open the popover
showOnKeyDown={ false }
>
<div>{ computedRenderSelectedValue( currentValue ) }</div>
Copy link
Member Author

Choose a reason for hiding this comment

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

div is unnecessary.

@@ -82,12 +82,12 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
);

return (
<>
<Styled.SelectedExperimentalHintWrapper>
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a wrapper div to apply text truncation styles as in v1.

Comment on lines -78 to -80
display: flex;
align-items: center;
justify-content: space-between;
Copy link
Member Author

Choose a reason for hiding this comment

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

No reason for this to be a flexbox.

Copy link
Contributor

@ciampo ciampo Jun 10, 2024

Choose a reason for hiding this comment

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

Knowing past Marco, there's a chance flexbox was used to automatically trim extra white space (although it's also very possible that this is a remnant of a previous style and it's totally fine to remove it)

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably totally fine to remove it :D

font-size: ${ CONFIG.fontSize };
text-align: left;
Copy link
Member Author

Choose a reason for hiding this comment

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

Text align was missing.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch 👍 I wonder how this didn't come up earlier.

Comment on lines +91 to +93
color: ${ COLORS.theme.foreground };
cursor: pointer;
font-family: inherit;
Copy link
Member Author

Choose a reason for hiding this comment

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

Correct color and font-family was missing.

width: 100%;

&[data-focus-visible] {
outline: none; // handled by InputBase component
}

${ getSize() }
${ ! hasCustomRenderProp && truncateStyles }
Copy link
Member Author

Choose a reason for hiding this comment

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

We shouldn't add truncate styles when the consumer passes a custom render function.

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.

Working well in my testing and the code looks good 👍

Thanks for cleaning up the styles while passing through!

@@ -55,40 +66,41 @@ export const Select = styled( Ariakit.Select, {
const sizes = {
compact: {
[ heightProperty ]: 32,
paddingInlineStart: space( 2 ),
paddingInlineEnd: space( 1 ),
paddingInlineStart: 8,
Copy link
Member

Choose a reason for hiding this comment

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

Is there a good reason to stop using the grid space util and hardcode the padding widths like that?

Copy link
Member

Choose a reason for hiding this comment

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

Curious about that, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

No big reason other than that I thought it was simpler to read in context, especially when I want to add the chevronIconSize like this. (space() returns a calc()).

font-size: ${ CONFIG.fontSize };
text-align: left;
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch 👍 I wonder how this didn't come up earlier.

Copy link
Member

@fullofcaffeine fullofcaffeine left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for working on this.

I started fixing other styling issues here: #62424 (it's been split from #), so I'll rebase from this, review the current issues, and continue working there.

# Conflicts:
#	packages/components/CHANGELOG.md
@mirka mirka merged commit 7bca2fa into trunk Jun 25, 2024
62 checks passed
@mirka mirka deleted the custom-select-v2-long-strings branch June 25, 2024 17:47
@github-actions github-actions bot added this to the Gutenberg 18.7 milestone Jun 25, 2024
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
4 participants