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

Fix select input components dropdown menu width #2699

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

CarlosCortizasCT
Copy link
Contributor

Summary

Fix select input components dropdown menu width

Description

We have an issue while calculating the width for the dropdown menu rendered when a select input component is clicked.
The problem is that we are using the minimum width configured also for the maximum width of that element:
image

Copy link

changeset-bot bot commented Jan 23, 2024

🦋 Changeset detected

Latest commit: 54bbd00

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 94 packages
Name Type
@commercetools-uikit/select-input Patch
@commercetools-uikit/select-utils Patch
@commercetools-uikit/data-table-manager Patch
@commercetools-uikit/pagination Patch
@commercetools-uikit/select-field Patch
@commercetools-uikit/inputs Patch
@commercetools-uikit/async-creatable-select-input Patch
@commercetools-uikit/async-select-input Patch
@commercetools-uikit/checkbox-input Patch
@commercetools-uikit/creatable-select-input Patch
@commercetools-uikit/date-input Patch
@commercetools-uikit/date-range-input Patch
@commercetools-uikit/date-time-input Patch
@commercetools-uikit/localized-money-input Patch
@commercetools-uikit/money-input Patch
@commercetools-uikit/search-select-input Patch
@commercetools-uikit/selectable-search-input Patch
@commercetools-frontend/ui-kit Patch
@commercetools-uikit/fields Patch
@commercetools-uikit/async-creatable-select-field Patch
@commercetools-uikit/async-select-field Patch
@commercetools-uikit/creatable-select-field Patch
@commercetools-uikit/date-field Patch
@commercetools-uikit/date-range-field Patch
@commercetools-uikit/date-time-field Patch
@commercetools-uikit/money-field Patch
@commercetools-uikit/search-select-field Patch
@commercetools-uikit/design-system Patch
@commercetools-uikit/calendar-time-utils Patch
@commercetools-uikit/calendar-utils Patch
@commercetools-uikit/hooks Patch
@commercetools-uikit/i18n Patch
@commercetools-uikit/localized-utils Patch
@commercetools-uikit/utils Patch
@commercetools-uikit/accessible-hidden Patch
@commercetools-uikit/avatar Patch
@commercetools-uikit/card Patch
@commercetools-uikit/collapsible-motion Patch
@commercetools-uikit/collapsible-panel Patch
@commercetools-uikit/collapsible Patch
@commercetools-uikit/constraints Patch
@commercetools-uikit/data-table Patch
@commercetools-uikit/field-errors Patch
@commercetools-uikit/field-label Patch
@commercetools-uikit/field-warnings Patch
@commercetools-uikit/grid Patch
@commercetools-uikit/icons Patch
@commercetools-uikit/label Patch
@commercetools-uikit/link Patch
@commercetools-uikit/loading-spinner Patch
@commercetools-uikit/messages Patch
@commercetools-uikit/notifications Patch
@commercetools-uikit/primary-action-dropdown Patch
@commercetools-uikit/stamp Patch
@commercetools-uikit/tag Patch
@commercetools-uikit/text Patch
@commercetools-uikit/tooltip Patch
@commercetools-uikit/view-switcher Patch
@commercetools-uikit/accessible-button Patch
@commercetools-uikit/flat-button Patch
@commercetools-uikit/icon-button Patch
@commercetools-uikit/link-button Patch
@commercetools-uikit/primary-button Patch
@commercetools-uikit/secondary-button Patch
@commercetools-uikit/secondary-icon-button Patch
@commercetools-uikit/localized-multiline-text-field Patch
@commercetools-uikit/localized-text-field Patch
@commercetools-uikit/multiline-text-field Patch
@commercetools-uikit/number-field Patch
@commercetools-uikit/password-field Patch
@commercetools-uikit/radio-field Patch
@commercetools-uikit/text-field Patch
@commercetools-uikit/time-field Patch
@commercetools-uikit/input-utils Patch
@commercetools-uikit/localized-multiline-text-input Patch
@commercetools-uikit/localized-rich-text-input Patch
@commercetools-uikit/localized-text-input Patch
@commercetools-uikit/multiline-text-input Patch
@commercetools-uikit/number-input Patch
@commercetools-uikit/password-input Patch
@commercetools-uikit/radio-input Patch
@commercetools-uikit/rich-text-input Patch
@commercetools-uikit/rich-text-utils Patch
@commercetools-uikit/search-text-input Patch
@commercetools-uikit/text-input Patch
@commercetools-uikit/time-input Patch
@commercetools-uikit/toggle-input Patch
@commercetools-uikit/spacings-inline Patch
@commercetools-uikit/spacings-inset-squish Patch
@commercetools-uikit/spacings-inset Patch
@commercetools-uikit/spacings-stack Patch
@commercetools-uikit/buttons Patch
@commercetools-uikit/spacings Patch
visual-testing-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 23, 2024 2:59pm

Comment on lines +167 to +173
'minMenuWidth',
Constraints.getAcceptedMaxPropValues(2),
3
)}
maxMenuWidth={select(
'maxWidth',
Constraints.getAcceptedMaxPropValues(),
'maxMenuWidth',
Constraints.getAcceptedMaxPropValues(4),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just using better names for the knobs and use the proper default and available values.

props.maxMenuWidth ?? getHorizontalConstraintValue(props.maxMenuWidth),
maxWidth: props.maxMenuWidth
? getHorizontalConstraintValue(props.maxMenuWidth)
: designTokens.constraintScale,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If no maxMenuWidth is provided, we use 'scale' as the default value.

designTokens.constraint3
);
const designTokenSuffix =
typeof value === 'string' ? upperFirst(value) : value;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the scale value is provided, we need a little transformation as its related token name is constraintScale.

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines 104 to 106
const constraintValue =
designTokens[`constraint${designTokenSuffix}` as TDesignTokenName] ||
designTokens.constraint3;
Copy link
Contributor

@kark kark Jan 23, 2024

Choose a reason for hiding this comment

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

I think if the current minMenuWidth or maxMenuWidth is auto, then constraintValue will fall back to designTokens.constraint3 here. Not sure if this is correct.
Screenshot 2024-01-23 at 14 18 26

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I also have doubts about this. Maybe @FilPob can help us what should the 'auto' prop do in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out.

I had another implementation alternative that I discarded at last minute but I think is better.

Please take a look at the changes here: 54bbd00

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, Carlos. I agree, this is a better solution.

Copy link

Choose a reason for hiding this comment

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

Honestly I am also not very sure what that auto option is doing :D But maybe it doesnt really make sense to have that option available for min.width and max.width.... I can image if you have just one "width" as a prop that the value gets calculated automatically somehow. But setting both min.width and max.width to auto doesnt make sense does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's try to get this merged so we fix the bug and we can customize the available options as a follow-up 🙏

@@ -94,13 +94,17 @@ type TState = {

type TDesignTokenName = keyof typeof designTokens;

const upperFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can use upperFirst from lodash, since it's already a dependency in this package

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 checked the main package.json file and didn't see that dependency so I assumed we were not using it in this repository 🤦

Anyway, with the new approach we don't need that utility anymore.

@FilPob FilPob self-requested a review January 23, 2024 13:02
default:
return (
designTokens[`constraint${value}` as TDesignTokenName] ||
designTokens.constraintScale
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From this helper point of view, I think it's safer to default to 100%.

Using this approach, even if we don't transform the incoming scale value, we will return that value anyway.

Copy link
Contributor

@chloe0592 chloe0592 left a comment

Choose a reason for hiding this comment

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

Thanks so much for the quick fix! 🙏

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Thanks again for the fix!

@CarlosCortizasCT CarlosCortizasCT merged commit 20dc5bb into main Jan 23, 2024
6 checks passed
@CarlosCortizasCT CarlosCortizasCT deleted the cm-fix-select-inputs-dropdown-width branch January 23, 2024 15:43
@ct-changesets ct-changesets bot mentioned this pull request Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants