-
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
Avoid adding default block to empty widget areas in customizer #32979
Conversation
Hmm, seems like it shouldn't do this when edit: ah, I think I see it, |
Size Change: +146 B (0%) Total Size: 1.04 MB
ℹ️ View Unchanged
|
There might be other things, like the Insert Before / After are no longer available since they insert the default block. Possibly other bits of functionality that's lost too. (edit: the slash inserter also doesn't work)
I feel like this would be good, but we also need the block not to be there in the editor. Maybe an option is an |
packages/customize-widgets/src/components/sidebar-block-editor/index.js
Outdated
Show resolved
Hide resolved
bf93753
to
ae1c58b
Compare
! ownerDocument.activeElement || | ||
ownerDocument.activeElement === ownerDocument.body |
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'm not sure we need this, but in case if the focus is intentionally moved to other element then we don't want to hijack it either.
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.
This works well.
We know it's not the ideal solution, but it's not too far away IMO, just need to find a way to detect the existence of a custom appender, rather than use a manual setting. And also think about other ways to handle moving the focus to the button appender.
E2E failures seem unrelated, I restarted these tests. |
Description
Fix #32968.
The block editor will inject a default block whenever the content is empty, preventing it from losing focus. This doesn't play nice in the Widgets Customizer though, as an empty block will still create a widget and thus pollute the sidebar. The standalone widgets screen doesn't suffer from this because it will never be emptied, there's always going to be Widget Area blocks.
The solution is to unregister the default block in the customizer, so that the editor won't try to insert a default block whenever the editor is empty. This has a side-effect though as now the focus will be lost after deleting the last block. A possible solution to that would be to manually move the focus to the button block appender whenever that happens.
Another solution to this problem would be to skip creating the empty widget when there's only one block and which is an empty default block. This is more semantically correct and we won't lose the focus. But it might be confusing to the users though 🤔.
I'm open to any other suggestions.
How has this been tested?
Screenshots
Kapture.2021-06-25.at.15.05.39.mp4
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).