-
Notifications
You must be signed in to change notification settings - Fork 4.7k
CustomSelect: adjust renderSelectedValue to fix sizing
#57865
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
Conversation
ciampo
left a comment
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.
Nice find! I believe that we can achieve the same result with fewer changes, and while keeping the defaultRenderSelectedValue external to the component's render function.
We could remove the default assignment to the renderSelectedValue (as you already did in this PR), and basically move the "use the default value if no value is provided" logic in the components' render function — something like
const computedRenderSelectedValue = renderSelectedValue ?? defaultRenderSelectedValue
We could then use computedRenderSelectedValue instead of renderSelectedValue in the JSX code.
What do you think?
Sounds great! I've implemented your solution in: dc2635e |
ciampo
left a comment
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.
LGTM 🚀
Good to merge after adding a CHANGELOG entry :)
This reverts commit 924ce00a894d820a7213412cdec9dbaa6a6cf7d0.
dc2635e to
96f0890
Compare
|
Flaky tests detected in 96f0890. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7563884228
|
|
There are some e2e failures (Firefox getting a 500 server error) that are not related to the changes from this PR, especially because the affect code is not used nor exported by the |
What?
When creating the component, we introduced logic to have better default values for rendered select values. However, this affected the sizing styles, which relied on the boolean
hasCustomRenderPropto check ifrenderSelectedValueis true or not. In trunk,renderSelectedValuewill always returntrueso the styles aren't applying as expected.Why?
To ensure the component size can be changed via the
sizeprop.How?
To fix this, we can remove
defaultRenderSelectedValueas the default value forrenderSelectedValueand instead invoke the function only whenrenderSelectedValueistrue.If
renderSelectedValueisfalse, thecurrentValuewill be used, and if that is empty, Ariakit uses the first available value.Testing Instructions
npm run storybook:devCustomSelectControl V2storysmallare applied to the 'Default' story (they won't apply to the other stories, wherehasCustomRenderPropistrue.