-
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
Block Spacing: Don't show UI when only one direction is supported #47523
Conversation
Size Change: +32 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
9f4a839
to
b51636c
Compare
Thanks for opening this PR! I've just added some comments over on the linked issue (#47518 (comment)) as the axial controls for block spacing were built assuming that opting in to a single direction would not be supported. In short, my main question is, what's the use case for defining a single direction over using While the change in this PR fixes the UI issues, the output uses a fallback gap for the opposing direction (e.g. So, in order to support passing in one direction, I think it would also involve updating the layout support output to support only outputting a particular Because it would involve changing things in a few places, I think it'd be good to better understand the use case for a single direction in Thanks again for all the digging in here @t-hamano! |
b51636c
to
6b5c17a
Compare
This PR was originally intended to correct the UI to work properly when supporting one direction. However, one direction support is not expected. Based on this discussion, I have made it so that when only one direction is supported, a console error is displayed instead of showing the UI. |
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.
Nice one, thanks for continuing on with this @t-hamano, and for the thorough consideration surrounding all of the potential values for blockGap
in block.json
!
This is testing well for me:
✅ Common UI is displayed when expected (true
value, empty array, or sides
prop set to empty array or false
)
✅ Axial pair are available when using array containing both vertical
and horizontal
or sides
prop containing the same
✅ Existing critical error for sides: true
looks fine to me
✅ Warnings displayed correctly when only a single direction is set
LGTM! ✨
Fixes #47518
What?
This PR
fixes a problem in which values are not reflected correctly in the controldoesnt't display the UI control and output a console warning message when the block supports only one direction insupports.spacing.blockGap
property.Why?
The attribute stored by
blockGap
holds only two properties, top and left. However, components such asBoxControl
that pass this value must specify all side values. Therefore, property mapping is performed in the following part:(Deleted)
If only one direction is supported (i.e.,
splitOnAxis
istrue
),undefined
values may enter some of the properties in this part of the property mapping.This will cause the component receiving the value to behave in an unintended way.
@update: Based on this discussion, the UI itself should not be displayed as it is not intended to support only one direction.
How?
Remove properties with undefined values.This process could be accomplished with the cleanEmptyObject function alone, but this function depends on lodash. I used this approach because I know that the move away from lodash is being promoted by #17025.If blockGap does not support both axes, the UI is not displayed and a warning message is displayed in the browser console.
Testing Instructions
blockGap
.block.json
, change this support as follows and confirm that the expected results are obtained.A common UI for both axis sides should be displayed
"blockGap": [],
"blockGap": true,
"blockGap": { "sides": [] },
"blockGap": { "sides": false },
UI should not be displayed
Behavior is the same as before.
"blockGap": false,
A single UI control for each axial pair should be displayed
Behavior is the same as before.
"blockGap": [ "vertical", "horizontal" ],
"blockGap": [ "vertical", "horizontal", "other" ],
"blockGap": { "sides": [ "vertical", "horizontal" ] },
"blockGap": { "sides": [ "vertical", "horizontal", "other" ] },
Critical Error
Behavior is the same as before.
"blockGap": { "sides": true },
UI should not be displayed with console warning
This PR prevents unintended UI rendering in the following variations.
"blockGap": [ "vertical" ],
"blockGap": [ "horizontal" ],
"blockGap": [ "vertical", "other" ],
"blockGap": { "sides": [ "vertical" ] },
"blockGap": { "sides": [ "horizontal" ] },
"blockGap": { "sides": [ "vertical", "other" ] },