-
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
Features like pattern overrides and block bindings have limited control over block UI #58233
Comments
I have some ideas about possible solutions to this, but wanted to keep the conversation open to other ideas, so didn't document it in the description. One of the issues that we have right now is that our controls from the components package are only aware of values: <TextControl value={ title } onChange={ onTitleChange } /> There's no awareness of the attribute declaration. I think we could consider changing this: <TextControl attribute="title" value={ title } onChange={ onTitleChange } /> This second version of the control that has awareness of the attribute wouldn't come from the components package, but instead either the block editor package or a new package (e.g. 'block controls'). This package would re-export the existing components, but perform some extra business logic in the controls, for example, the 'block controls' version of import { TextControl } from '@wordpress/components';
import { useBlockBindingStatus, useBlockControlVisibility } from '@wordpress/block-editor';
export default function TextControl( { attribute, ...props } ) {
const isVisible = useBlockControlVisibility( attribute );
const bindingStatus = useBlockBindingStatus( attribute );
if ( ! isVisible ) return null;
return <TextControl { ...props } status={ bindingStatus } />;
} I think this would help us avoid having to write complex logic within blocks. The major downside is that the scope of this is pretty huge, gradually replacing the controls for blocks. Third parties could also adopt this but the process could be quite slow. |
Excellent ideas @talldan. I have been talking to @SantosGuillamot about improving the current
I also was thinking about other optimizations to improve the developer experience and better support the block bindings integration in #58085 (comment):
We also touched on a helper React hook that would simplify the check for binding status. This is what I drafted:
I think that's a viable approach and worth the hassle! |
Something I've always been wondering about is how we made it work with content only locking. I understand that there is a flag called In theory I still quite like the API for having the definition for what a field is live with the attribute definition. But I never understood how that connection between the UI control and the attribute is made |
In gutenberg/packages/block-editor/src/hooks/duotone.js Lines 123 to 125 in 6c86365
So right now the onus is really on the implementor of the control to handle its visibility. I think I'd like to see that inverted so that a UI control implicitly handles its own visibility. |
I think block-developers implementing controls should always have the possibility, to define when their component should render - because a TexttControl might be used for some "content-related" attributes but maybe also for others (e.g. the field for custom CSS class names)? If I'm building a custom block, I might want to define "this control is content-related, this one is not". But on the other side, as a developer using core/3rd party blocks, I would want to overwrite those conditions sometimes - for example based on attribute bindings, the permissions of the user (to make permissions in editing more granular), etc. Having the role (e.g. __experimentalContent) on the attribute doesn't always make sense either - because a string attribute may be content, but have a binding (or pattern override) and therefore still shouldn't be shown. Also, we have to think about object-type attributes - like the queryArgs in the core/query block. There's just one attribute, but all the sub-properties are connected to single controls and those controls can be enabled/disabled in variations. Inheriting the query is kind of like an "edit-mode" here as well - because all the controls are disabled them. I always thought that the "structureless" rendering of controls inside in React makes it hard to disable/enable only some of them. E.g. via SlotFills one can actually only add controls, but never remove controls (so kind of like the concepts of do_action vs. apply_filters). Those are just thoughts, I have no concrete useful input/ideas 😅 |
What's the problem?
Several features require a way to manage specific block attributes and the UI controls for those attributes in a way that's difficult currently:
useBlockEditingMode( 'contentOnly' )
to manage the visibility of block controls. This hides the majority of block controls that are considered unrelated to content. The waycontentOnly
works is very inflexible—it completely hides the block inspector, even if there are content controls there (like the image block alt/title fields). It also doesn't do a great job of managing toolbar controls—lots of blocks have internal conditional logic for handling the visibility of controls based on the block editing mode, which becomes hard to manage. There's a problem in that the controls displayed or hidden are a fixed list that has no relation to the pattern overrides supported attributes. Changing the visibility of UI controls will also affect other usages ofuseBlockEditingMode( 'contentOnly' )
outside of patterns.Offering better management over block attributes and controls might also tie into future initiatives around workflows and extensibility.
My feeling is that these problems are closely related, and this is an area that needs some exploration.
The text was updated successfully, but these errors were encountered: