LineHeightControl: Fix application of zero values in editor#48917
LineHeightControl: Fix application of zero values in editor#48917aaronrobertshaw merged 3 commits intotrunkfrom
Conversation
|
Size Change: +15 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
talldan
left a comment
There was a problem hiding this comment.
LGTM, the changes all make sense.
Left some comments, but they're mostly optional, though it'd be good to fix the types in the doc block before merging.
packages/block-editor/src/components/line-height-control/index.js
Outdated
Show resolved
Hide resolved
9bbb0f8 to
e55615b
Compare
aaronrobertshaw
left a comment
There was a problem hiding this comment.
I've updated the approach in light of @youknowriad's feedback advising as to how we can avoid the need to update cleanEmptyObject.
The latest approach in this PR works for me against trunk's cleanEmptyObject or the version in #49750.
I've left a few inline comments as to the changes that remain but the PR is now more trivial.
| ); | ||
| }; | ||
| const hasLineHeight = () => !! value?.typography?.lineHeight; | ||
| const hasLineHeight = () => value?.typography?.lineHeight !== undefined; |
There was a problem hiding this comment.
I've kept this tweak to the line height value detection so it can correctly check any old numeric line-height values that might be 0 in existing blocks/styles.
| if ( nextValue === '' ) { | ||
| onChange(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
This is needed if we land #49750 which changes cleanEmptyObject to keep anything that !== undefined.
It also allows the following onChange calls to simply convert the value to a string improving zero value handling.
|
Now #49750 has been merged, I've re-tested this PR after rebasing on trunk and it still works well. I'll get this merged. |
Fixes: #48768
What?
Prevents LineHeightControl resetting and clearing values when
0line height selected.Why?
While zero line height might be an uncommon use case, as long as we allow zero as the minimum value for the control it should be honoured and remain when continuing to drag down, or use the down arrow key.
How?
Boolean()) or #49750 (!== undefined). The control'shandleOnChangewill then ensure any defined line-height value is passed to it's onChange handler as a string.Testing Instructions
Screenshots or screencast
Screen.Recording.2023-03-08.at.7.14.49.pm.mp4
Screen.Recording.2023-03-08.at.7.02.54.pm.mp4