-
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
Selected blocks get deleted when creating a reusable block and pressing backspace key #36513
Comments
Copying report from duplicate issue #37539: Originally reported in WordPress Core's Trac ticket 54652. Since WordPress 5.9 Beta (works correctly in 5.8.1), backspacing to clear the reusable block's name in the "Create Reusable Block" modal closes the modal and deletes the selected blocks. This is different from WordPress 5.8.1 which clears the name field, but keeps the modal open and does not delete the selected blocks. The reporter also notes that control Z does not restore the content; however, in my testing, control Z did restore the blocks for me. Step-by-step reproduction instructions
Notice the modal closes and the selected blocks are deleted. Screenshots, screen recording, code snippetEnvironment info
|
Test Report from @costdev: Environment Info
Removing this event listener removes the
|
The issue was introduced via #32323 or with Gutenberg 11.2. React events correctly bubble through portals and are caught by Short term solution for WP 5.9 could be to modify We should probably constrain shortcuts to Modals in the long term, like with tabbing. /cc @WordPress/gutenberg-core |
Sounds to me like key detection in the content should check DOM events instead of React events. |
I discussed this with @ellatrix and will have a PR today with a possible solution without reverting. |
I think this boils down to the question: do we want shortcuts to work when the options popover in the block toolbar is toggled (which shows some shortcuts). I think yes. In that case this popover is no different from any other thing that uses a portal (iframe, inspector...). There's no way to know where exactly ⇧⌘D (for example) should work. If we want it to work in the block toolbar popover, then it will also work in the inspector and modals created in a block because they're all nested in the same BlockTools tree. Solution 1: check if the target element is a text area, input, content editable, or event.defaultPrevented is true and return early. In all these cases backspace could be handled elsewhere. Solution 2: remove "basic" shortcuts like backspace from this event handler and restrict them to only work when the block in the canvas is focused. This would disable these basic shortcuts if the "more options" popover is focussed, but also when focus is in the inspector or a modal created by the block. Solution 3: More specifically add the keydown handler to certain wrappers: only to the block props (so it works when the block has focus), and the block toolbar. Seems harder for multi block shortcuts, so it may have to be added to block list element. The idea is that there would be multiple instances of event handling: one for focus in the content and one for focus in the block toolbar instead of a single one to catch it all. |
Description
When creating a reusable block via selecting multiple blocks, pressing the backspace key when typing a name in the "Create Reusable block" dialog leads to deleting the selected blocks and therefore the dialog to disappear. This behavior makes it very difficult to create a reusable block as removing characters when setting a name is very common.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
reusable-block-backspace-bug.mp4
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: