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

Fixed: Dimensions Custom Unit behaviour is not working as expected #68740

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

Mayank-Tripathi32
Copy link
Contributor

@Mayank-Tripathi32 Mayank-Tripathi32 commented Jan 17, 2025

fixes #68734

What?

The issue occurs when changing the typography dimensions (e.g., padding/margin) from "Use size preset" to "Set Custom Size" and switching the unit type from px to another unit. The selected unit resets back to px, requiring users to select their desired unit twice.

Why?

  • Reset Behavior: The code resets the value due to improper handling of the selected unit and the fallback logic in the getValidParsedQuantityAndUnit function.
  • Unit Validation: The nextValue computation doesn't persist the new unit properly, resulting in an override to the default (px).
  • User Experience Issue: This creates unnecessary friction, as users need to repeat actions to achieve the intended result.

How?

The fix ensures the selected unit is preserved during the transition by improving the logic inside the getValidParsedQuantityAndUnit function:

  • Introduced validation to check the current and next units.
  • Applied fallback logic only when needed (e.g., reset defaults only if explicitly required).

Testing Instructions

  1. Select any block paragraph, pullquote, quote, etc.
  2. Add dummy text
  3. Go to block settings and change "Typography Dimensions" from "Use size preset" to "Set Custom Size"
  4. Now, change its type from "px" to any other based on requirement
  5. Now, change size using range control.

Screencast

Screen.Recording.2025-01-17.at.4.24.55.PM.mov

@Mayank-Tripathi32 Mayank-Tripathi32 changed the title Fixed: Dimensions Custom Unit behaviour is not working as expected. Fixed: Dimensions Custom Unit behaviour is not working as expected Jan 17, 2025
@Mayank-Tripathi32 Mayank-Tripathi32 marked this pull request as ready for review January 17, 2025 11:13
Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

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: Mayank-Tripathi32 <[email protected]>
Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: viralsampat-multidots <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

While I haven’t tested this, I trust it fixes the issue yet I doubt that changing code in UnitControl is the best approach. That’s because I’ve tested another component BoxControl that also pairs UnitControl with a range input and it doesn’t have the same issue.

Here’s a quick demo trying to reproduce the issue in the BoxControl story:

box-control-empty-non-px-unit-and-range-drag.mp4

That leads me to think the issue is somewhere in SpacingSizesControl. Would you agree?

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.

Block Typography Dimensions Custom size behaviour is not working as expected.
2 participants