-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fixed Input Unit Block: Unit jumps to px when set to 0 #68212
base: trunk
Are you sure you want to change the base?
Fixed Input Unit Block: Unit jumps to px when set to 0 #68212
Conversation
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 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. |
If the proposed changes seem correct, I can update the failing unit tests in each component to handle value instead of undefined. This adjustment will align the tests with the updated behavior and ensure they pass as expected. |
It seems the test cases expects the default behaviour of "undefined", So I think its better to introduce a prop "shouldPreserveUnit" and conditionally add it for required places. |
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.
Works as expected ✨
Screen.Recording.2025-01-20.at.4.54.56.PM.mov
The screen recording you posted doesn’t show properly testing #51616, which requires the Spacer block to be inside a Row/Stack. The issue wasn’t very clear about that. I missed it too #51616 (comment) when I was trying to reproduce the issue initially. I'm not doubting this PR fixes the issue. The description includes a screen recording demonstrating an actual test of the issue. @Mayank-Tripathi32, Why does fixing this require changes to |
fixes #51616
What?
This PR fixes the issue where the unit in the spacer and dimension controls resets to px when the input value is cleared.
Why?
When removing the value from input fields like spacer height or padding in the dimensions control, the unit automatically resets to px. This behavior causes unexpected results and reduces user control over custom styles. Fixing this improves usability and ensures a consistent editing experience.
How?
The fix was applied in packages/components/src/unit-control/index.tsx, where the unit was being dropped when the input value was cleared. The implementation now ensures that when the value is empty, it defaults to 0 with the current unit preserved, preventing the reset to px.
Testing Instructions
Additional Test:
Screencast
test-unit-controls.mp4