-
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
Theme Support: Enable custom units by default #24873
Conversation
Size Change: +16 B (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
|
||
```php | ||
add_theme_support( 'custom-units', 'rem', 'em' ); | ||
add_theme_support( 'custom-units', false ); |
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 we should change this to remove_theme_support( 'custom-units' );
and add a add_theme_support( true )
call to Core.
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.
Cool! That API makes sense to me. I've never worked with remove_theme_support
before.. Is there an example I can follow to do that? :D
Shouldn't the specific units be a single array argument instead of spread arguments? |
@mtias I'd lean on the opinions of others on this one!
|
I'd keep it as is just because it's already on WP 5.5. Ultimately, all these options will be configured using theme.json |
Sounds good |
Closing, if favour of: |
This update enables custom units by default. Custom units can be disabled using
add_theme_support( 'custom-unit' )
and setting it tofalse
, like so:A quick enhancement for this: #23964 (comment)
Thinking behind this approach
Since the
experimental
flag was removed fromcustom-unit
, I felt hesitant changing that filter key. Unlike some of the other design tool filters, this one acts as more than just aboolean
value.For instance, themers can filter certain units by doing the following:
(The above would use only
em
andpx
).Instead of adding something like
add_theme_support( 'disable-custom-unit' )
... I preserved thecustom-unit
theme support key, but adjusted the way it could be used to disable + filter units.Default: Custom units on
Disable: Custom units off
Filtering: Custom units on, but filtered
Working with (global) custom units
At the moment, Cover appears to be the only core block that uses
UnitControl
, specifically for height and padding.For the units to respect the
add_theme_support
, the component (or hook) must come from:This will have the theme-configured units pre-bound:
When working within
block-editor
, you can use the hook to receive pre-filtered units:Working with
UnitControl
The recommended implementation of
<UnitControl />
would be this setup:The unit value (
string
) contains both the value and the unit.isPressEnterToChange
is important as it allows users to type in custom values, e.g.12345px
. The change only applies onENTER
press (or blur).This is how it's setup with Cover's padding controls (via
BoxControl
).An older (initial) implementation looked like this (Cover's height controls):
Notice how the
value
andunit
is tracked separately. Also, there isn'tisPressEnterToChange
, therefore the changes are applied immediately.Adding custom units
If you need to add custom units to your control (e.g.
vmin
,%
, etc...), you can do so like this:This will allow you to adjust unit values based on different design contexts.
An example of this can be seen in Cover:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/cover/shared.js#L21
How has this been tested?
Checklist: