-
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
[Columns] Width listed in px rather than percentage #34096
Comments
Seem there is an issue in themes that customize the spacing units. The TT1 theme does this here: https://github.com/WordPress/theme-experiments/blob/10dc98f4bb3848d3a70078a165668572992e57e1/tt1-blocks/theme.json#L178-L187 "spacing": {
"customPadding": true,
"units": [
"px",
"em",
"rem",
"vh",
"vw"
]
}, Note that the TT1 theme doesn't have When inserting the columns variations the gutenberg/packages/block-library/src/columns/variations.js Lines 76 to 79 in 1f186b9
Not sure the best approach to solve this issue. Should percentages always be allowed in |
Oh wow! Thanks for this excellent sleuthing. Going to add in more labels to expand this conversation. |
This is an interesting problem. It's especially noticeable when trying to reset a column's width values: columns.mp4If I change the values/units, then remove them I can't return to the original width values and have to create a new column. I wonder what our options are. I'm just rattling off some un-informed ideas to get things started. If block variations natively require a specific unit, where should the compromise lie? Should the block itself enforce the use of Allow block.json to define 'always-on' unit valueIf we allow the block to tell theme.json what to do, we could perform a merge of customUnits, for example, using the arguments for useCustomUnits (so the columns block.json can define an immutable ❗ I'm not sure the benefit would outweigh the obvious con, that is, it would dilute the authority of Restore initial variation valueMaybe a lower barrier would be to store the initial value, e.g., TransformCould we create custom transforms or variations depending on the unit value. Perhaps in the onSelect callback of This assumes of course that we have access to the custom units, and can check them against the units required by variations.js, AND then come up with a suitable replacement value depending on the unit. For example, This seems like the most work. I'd be very happy to learn about better ways to approach this! |
That's a compelling idea @ramonjd — it feels like the Columns block has been built expecting that the percentage unit will be available, so I quite like the idea of a block being able to define an immutable unit. I wonder what the consequences would be for theme authors? In the case of TT1-blocks, where the units value is set globally, having an individual block take care of its own required units means that the theme author doesn't have to worry about potentially breaking block behaviour, so it could be beneficial, even if it's unexpected? |
I've run into this issue as well — resetting to |
I'm just assigning myself to this one, I thought I'd see if I can come up with a fix for the Column block when the width is set to a value that isn't supported by the |
I have a PR ready for review in #34768 that attempts to deal with this issue by ensuring that the UnitControl will always display the current value's unit (if it's a valid CSS unit) irrespective of the theme's list of allowed units. If a theme provides a more limited list of available units, then once the unit of the current value is switched away from the not-allowed-unit, then the provided list is respected. I think this should resolve the issue for the Columns block requiring percentage widths for its variations, while also ensuring that we don't run into similar issues with other blocks. Very happy for feedback, though, if folks think there's a better way to handle it! |
Description
When adding in columns, the width is listed as px rather than percentages.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
column.percentage.mov
Environment info
Pre-checks
The text was updated successfully, but these errors were encountered: