Skip to content
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

Prevent focus loss when deleting all blocks #9626

Closed
jasmussen opened this issue Sep 5, 2018 · 3 comments
Closed

Prevent focus loss when deleting all blocks #9626

jasmussen opened this issue Sep 5, 2018 · 3 comments
Assignees
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement.

Comments

@jasmussen
Copy link
Contributor

Extracted from #8961 (comment).

Problem: If you delete all blocks on a post or page, focus is lost.

Steps to reproduce:

  1. Insert a bunch of blocks. Try the demo content.
  2. Press ⌘A to select all blocks (⌘A twice if your caret is in text first)
  3. Press del to delete those blocks.

Notice how focus is lost (it's actually on the body element).

Propost solution:

When all blocks are deleted, simply set focus on the first appender:

screen shot 2018-08-31 at 11 34 29

CC: @talldan

@jasmussen jasmussen added [Type] Enhancement A suggestion for improvement. [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Sep 5, 2018
@aduth
Copy link
Member

aduth commented Sep 5, 2018

As far as implementation, the obvious path seems to be that when the last block is removed, we insert and focus the default block. However, this raises a few questions:

  • What happens when the only thing left is the empty paragraph and the user wants to remove it?
    • Related Slack discussion (link requires registration)
    • If we say that the default block is inserted when the last of all blocks are removed, that means that if I'm already in the default empty block and remove it, I'll be forever trapped in this repeated cycle of default block insertion.
    • Recommendation: Maybe that's okay. And maybe we should change the serialization step to account for the fact that a post which only includes the "empty default block" should not include any content (rather than the empty paragraph tag with delimiters).
  • Is a similar behavior needed for blocks within a nested context?
    • Recommendation: It's not as easy to account for the issue described in the first point, so while technically inconsistent it might be better to reserve this behavior for top-level blocks removal only.
  • What if the default block is not the paragraph block? A custom post type could, for example, assign core/image as the "default" block type. This is technically supported.
    • Recommendation: There may be a bigger question on the interactions of non-paragraph default blocks, but in other cases we apply the behavior consistently as well (e.g. "default block appender") so it should be a non-issue.

@jasmussen
Copy link
Contributor Author

If we say that the default block is inserted when the last of all blocks are removed, that means that if I'm already in the default empty block and remove it, I'll be forever trapped in this repeated cycle of default block insertion.

That is an interesting point.

Recommendation: Maybe that's okay. And maybe we should change the serialization step to account for the fact that a block which only includes the "empty default block" should not include any content (rather than the empty paragraph tag with delimiters).

I like this.

A Plan B could be to set focus on the title block instead. A plan C could be to set focus on the editing canvas, so a single press of Tab sets focus on the title. Right now focus is on body, so you have a great deal to tab through to get back to where you were.

Is a similar behavior needed for blocks within a nested context?

Depends? I think the key is to ensure focus is set on a sensible place when a block is deleted. Could be the preceeding block, which suggests focus could be set on the title if all blocks are deleted.

@afercia afercia added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Sep 6, 2018
@aduth aduth self-assigned this Sep 6, 2018
@aduth
Copy link
Member

aduth commented Sep 17, 2018

As of #9808, a post containing only an unmodified default block (paragraph) is now saved as empty.

This enables #9977, which implements the behavior proposed here in ensuring always a default empty block is inserted into the root of the editor upon removal / replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants