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: tweak item inline padding based on size #62850

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Jun 25, 2024

What?

Part of #55023

Match the CustomSelectControl V2 item inline padding with the dropdown trigger (button)

Why?

For better visual polish, and to match the V1 version of the component

How?

  • Forward the size prop from the root component to the item component via internal context
  • Use the size to apply the same horizontal padding that is applied to the select trigger button

In the process, I also refactored some common inline padding values to a separate variable

Testing Instructions

  • Open the CustomSelectControlV2 Storybook example
  • open the select dropdown and observe the horizontal spacing on the trigger button and each option item
  • tweak the size prop (and, optionally, the __next40pxDefaultSize prop)
  • make sure that the spacing around all items is well aligned

Screenshots or screencast

V1 V2 before (trunk) V2 after (this PR)
size.alignment.-.cscv1.mp4
size.alignment.-.cscv2.before.mp4
size.alignment.-.cscv2.after.mp4

@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-size branch from 44855d9 to 8012f91 Compare June 26, 2024 12:44
@ciampo ciampo changed the title CustomSelectControlV2: change item horizontal padding based on size prop CustomSelectControlV2: tweak item inline padding based on size Jun 26, 2024
@ciampo ciampo marked this pull request as ready for review June 26, 2024 13:09
@ciampo ciampo requested a review from ajitbohra as a code owner June 26, 2024 13:09
@ciampo ciampo requested a review from a team June 26, 2024 13:10
@ciampo ciampo self-assigned this Jun 26, 2024
Copy link

github-actions bot commented Jun 26, 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: 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.

@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Jun 26, 2024
@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-size branch from 829974f to 03cff84 Compare June 27, 2024 08:48
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.

Nice work on getting proper consistency with v1 👍 So cool to see the v2 getting closer and closer!

Left some minor feedback, feel free to treat everything as optional and non-blocking.

🚀

packages/components/src/custom-select-control-v2/styles.ts Outdated Show resolved Hide resolved

export const SelectedItemCheck = styled( Ariakit.SelectItemCheck )`
display: flex;
align-items: center;
margin-inline-start: ${ ITEM_PADDING };
margin-inline-start: ${ space( 2 ) };
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 not immediately clear why we're using space( 2 ) here but we use the hardcoded INLINE_PADDING values in other areas.

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 stopped using the ITEM_PADDING variable because, IMO, the space between the item's contents and the checkmark is not tied to the item padding. Using that variable was misleading (especially as, in this PR, we add variable padding based on the size prop). It just so happened that the margin before the check icon is the same as the padding for the small/compact variant of the component, but that's a coincidence

@@ -13,7 +13,11 @@ import { space } from '../utils/space';
import { chevronIconSize } from '../select-control/styles/select-control-styles';
import type { CustomSelectButtonSize } from './types';

const ITEM_PADDING = space( 2 );
const INLINE_PADDING = {
compact: 8, // space(2)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if a better way would be to just export GRID_BASE and do a compact: GRID_BASE * 2 calculation here?

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 see the reason behind your point, at the same time it feels this would warrant a bigger, separate conversation about the grid system and related utilities. I'd be inclined to keep it as-is and refactor (if necessary) separately.

@ciampo ciampo force-pushed the fix/custom-select-control-v2-item-size branch from 03cff84 to c49a4f3 Compare July 2, 2024 16:36
@ciampo ciampo enabled auto-merge (squash) July 2, 2024 16:56
@ciampo ciampo merged commit b67f00f into trunk Jul 2, 2024
63 checks passed
@ciampo ciampo deleted the fix/custom-select-control-v2-item-size branch July 2, 2024 17:13
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 2, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…ress#62850)

* Use context to forward size down to the option item

* Apply different paddings based on item size, matching the select button

* Use shared variables

* CHANGELOG

* Extract size calculations outside of styled element function

---

Co-authored-by: ciampo <mciampini@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.

2 participants