-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
templateLock
is a property of InnerBlocks
that allows you to "lock" an InnerBlocks area.
As implemented, it is somewhat limited, with only three options: prevent all modifications, prevent inserting, and disable locking (for nested contexts).
I'd like to see a slightly more flexible approach, which reflects different needs in various nesting situations. In particular, templateLock
doesn't currently have an option to disable inserting/removing while preserving movement, which I think could be a fairly common use-case (and what prompted me to submit this).
In this more granular approach, you would pass an array of blocked actions:
<InnerBlocks templateLock={['insert', 'move', 'remove']} />
// Could also be aliased as "all"
<InnerBlocks templateLock={['move']} />
// Newly-possible option — allow inserting/removing but no movement
<InnerBlocks templateLock={['insert', 'remove']} />
// Another newly-possible option — _only_ allows moving
<InnerBlocks templateLock={[]} />
// Pass an empty array, or "none", to undo the lock
// You could also continue to pass strings in to preserve back-compat
// (or just make for fewer characters in a user's code)…
<InnerBlocks templateLock="all" />
<InnerBlocks templateLock="none" />
<InnerBlocks templateLock="insert" />
<InnerBlocks templateLock="remove" />
Further, to better reflect that templateLock
does not require setting a template
(for example if you're building your block structure programatically by dispatching insertBlocks actions), it could be renamed disabledBlockActions
(e.g. <InnerBlocks disabledBlockActions={['move', 'remove']} />
), or something similar (perhaps disabledBlockUIActions
to be absolutely clear to developers that the locks only apply to the UI; you can still programmatically alter the block structure).
I believe this flexibility would be super valuable for anyone doing more complex things with InnerBlocks
. To me, InnerBlocks
is one of the most exciting features in Gutenberg and I think strengthening this API will have awesome benefits for developers.
(Note: my use-case is most focussed on InnerBlocks
, but I suspect these changes could be of use to custom post type templates as well!)