-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Components: Don't mutate 'ALL_CSS_UNITS' default value in 'useCustomUnits' #70037
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
cc @WordPress/gutenberg-components |
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @pryley. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
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.
Thanks for the PR! This change looks good to me.
I have confirmed that this issue occurs not only when the fallback units
value is used, but also when consumers provide shared values to multiple components, and this PR will also resolve that issue. Is my understanding correct?
Example:
export default function Component() {
const units = [
{ value: 'px', label: 'pixel' },
{ value: 'em', label: 'em' },
{ value: 'rem', label: 'rem' },
];
return (
<>
<UnitControl
isResetValueOnUnitChange
units={ useCustomUnits( {
availableUnits: [ 'px', 'em', 'rem' ],
defaultValues: { px: 8, em: 0.5, rem: 0.5 },
units,
} ) }
/>
<UnitControl
isResetValueOnUnitChange
units={ useCustomUnits( {
availableUnits: [ 'px', 'em', 'rem' ],
defaultValues: { px: 16, em: 1, rem: 1 },
units,
} ) }
/>
</>
);
}
That's correct, if |
44afb7e
to
bf2a79b
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.
LGTM 👍
…nits' (WordPress#70037) Unlinked contributors: pryley. Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
What?
Closes #70036.
PR fixes accidental
ALL_CSS_UNITS
value mutation when theunits
argument was provided foruseCustomUnits
.Why?
Testing Instructions
Testing Instructions for Keyboard
Same.