-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
FontSizePicker: Use number values when the initial value is a number #33679
Conversation
Size Change: -56 B (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
Thanks! :) |
Is it possible to fix the issue in |
Asking because this will fix |
The If we have to parse units into numbers there as well, then using |
I was thinking something like: if the passed (previous) value passed to That said, I still prefer this PR because the proposal is a hack but the hack might be necessary depending on the scale of the breaking change. |
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.
Maybe this is good enough as both reported issues are specifically about withFontSizes
So far, I've only seen reports about Side note: The problem can also be fixed by changing attribute type from "number" to "string." |
One question though about the fix here. It seems that the proposed fix assumes that only |
The But yeah, sadly, unit control values will have no effect. |
What was the behavior in WP 5.7? |
The What do you think about this idea?
|
Currently, I can think of the one issue with my proposed solution: if the user changes unit and attribute type is a number, it will trigger block validation. |
So we introduced units only in 5.7? In my mind, we did introduce that before but maybe I'm wrong? |
I think we introduced the units before, but we update NumberControl to UnitControl in FontSizePicker in 5.8. This is the PR - #31314. |
Ok, so it seems the best approach would be to revert the FontSizePicker to Also curious about @aristath's opinion here. |
Making the |
It looks like we already have gutenberg/packages/components/src/font-size-picker/index.js Lines 66 to 68 in ed8a7ad
I think we can use that check and do following: onChange( hasUnits ? nextSize : parseInt( nextSize, 10 ) ); This way, we'll consider the block's current attribute value and pre-defined sizes, allowing us to use units or numbers. I will update PR shortly to test this case. |
@aristath I'm not suggesting to revert but to make it optional (and enabled for all Core things) because switching the value from number to attribute is breaking all plugins that rely on the "value" of FontSizePicker being a number. |
dcd67bd
to
ccd9547
Compare
Removed original fix and updated It should fix the BC issue and allow developers to use units with FontSizePicker. |
@Mamaduka maybe I'm asking too much but I feel like we should have an e2e test with the provided plugin to avoid future regressions. WDYT? |
I think this case is more suited for unit tests - Or do you want to test that it doesn't trigger block validation and attributes are correctly defined?. |
Whatever works best for you :) |
Added unit tests. |
|
||
describe( 'FontSizePicker', () => { | ||
describe( 'onChange values', () => { | ||
it( 'should not use units when the initial value is a number', () => { |
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.
Should we check that the units input is not render or do you think it should be rendered in this case?
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.
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.
I think toggling between NumberControl and UnitControl based on has units value will introduce more complexity to the component.
Can't we just pass an empty array of units or something like that in that case? It feels weird for a user to select "em" but have pixels applied.
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.
Done. It will now only display the "PX" unit label when there are no units.
This is great for me, thanks for all the iterations. |
Not a problem. I'm just happy we were able to find the right way to fix this issue. |
…33679) * FontSizePicker: Don't use units if the value is a number * Add unit tests * Disable units when we have number values
* Fix API docs generation (#33384) * Docs: use markdown headings instead of links for API declarations (#33381) * Docs: Run Prettier after updating API in documentation (#33498) (cherry picked from commit 626f233) * Use tabs instead of spaces in block transform doc example (#33549) (cherry picked from commit 8afca1e) * Fix metabox reordering (#30617). * Block editor: don't render layout and duotone styles in between blocks (#32083) * Widgets: Allow HTML tags in description (#33814) * Widgets: Allow HTML tags in description * Use `dangerouslySetInnerHTML` Avoid `<div />` inside the `<p />` tag * Describe by dangerouslySetInnerHTML is used * Use safeHTML * Update comment * Editor: Set 'hide_empty' for the most used terms query (#33457) Don't include terms that aren't assigned to any posts as "most used" terms. * Update widget editor help links to point to the new support article (#33482) * If select-all fires in .editor-post-title__input, end the process.. (#33621) * Writing flow: select all: remove early return for post title (#33699) * Call onChangeSectionExpanded conditionally (#33618) * FontSizePicker: Use number values when the initial value is a number (#33679) * FontSizePicker: Don't use units if the value is a number * Add unit tests * Disable units when we have number values * Fix justification for button block when selected (#33739) * Remove margin setting, auto right conflict with justify buttons * Per review, add little margin back * Add error boundaries to widget screens (#33771) * Add error boundary to edit widgets screen * Add error boundary to customize widgets * Refactor sidebar controls provider to application level so that its state is not lost when re-initializing * Revert "Refactor sidebar controls provider to application level so that its state is not lost when re-initializing" This reverts commit 7d607ff. * Remove rebootability from customize widgets * Remove debug code * Fix insertion point in Widgets editors (#33802) * Default batch processor: Respect the batch endpoint's maxItems (#34280) This updates the default batch processor to make multiple batch requests if the number of requests to process exceeds the number of requests that the batch endpoint can handle. We determine the number of requests that the batch endpoint can handle by making a preflight OPTIONS request to /batch/v1. By default it is 25 requests. See https://make.wordpress.org/core/2020/11/20/rest-api-batch-framework-in-wordpress-5-6/. * Fix button block focus trap after a URL has been added (#34314) * Rework button block link UI to match RichText format implementation * Refine some more, determine visibility by selection and url state * Add e2e test * Also focus rich text when unlinking using a keyboard shortcut * Text for dropdown fields within legacy widgets in the Customizer is off centered (#34076) * Fix ESLint errors reported * Regenerate autogenerated docs * Update the `INSERTER_SEARCH_SELECTOR` path. This is a partial cherry pick of 2356b2d in order to fix the performance tests. Co-authored-by: André <nosolosw@users.noreply.github.com> Co-authored-by: JuanMa <juanma.garrido@gmail.com> Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl> Co-authored-by: Jeff Bowen <jblz@users.noreply.github.com> Co-authored-by: Bruno Ribarić <43731400+ribaricplusplus@users.noreply.github.com> Co-authored-by: Ella van Durpe <4710635+ellatrix@users.noreply.github.com> Co-authored-by: Petter Walbø Johnsgård <petter@dekode.no> Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> Co-authored-by: Daniel Richards <daniel.richards@automattic.com> Co-authored-by: Hiroshi Urabe <mail@torounit.com> Co-authored-by: Kai Hao <kevin830726@gmail.com> Co-authored-by: Marcus Kazmierczak <marcus@mkaz.com> Co-authored-by: Robert Anderson <robert@noisysocks.com> Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Description
Updates
onChange
logic in FontSizePicker component. When the component detects that value or first object infonSizes
doesn't use units, it will pass the number value to the onChange callback.Fixes #33651.
Fixes #33653.
How has this been tested?
Tested with plugin provided in original issue report - https://github.com/NasKadir123/textBlock
Types of changes
Bugfix
Checklist:
*.native.js
files for terms that need renaming or removal).