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

Blocks: Fix the black border appearing too often in blocks #5140

Closed
wants to merge 2 commits into from

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Feb 19, 2018

Sometimes when a block is selected by clicking on its surroundings (paragraph), a black border appears. This black border is only meant for blocks without any textual content (like image blocks, etc..) when they receive focus and isTyping is true (for example when navigating using arrows).

This PR adds a has-textual-content className for these blocks to avoid seeing this black border when we don't need it.

Nested blocks made this border appear too often.

Testing instructions

  • Try clicking and typing in paragraph blocks
  • Clicking on the margin/padding of the block
  • The block border should not appear.
  • It should only appear when navigating using arrows to these non-textual blocks.

@youknowriad youknowriad self-assigned this Feb 19, 2018
@jasmussen
Copy link
Contributor

This seems to work nice. However there appears to be a regression with this rectangle in general, perhaps unrelated to this PR:

rectangle

Notice that as soon as I insert a placeholder using the slash command, the placeholder itself doesn't have focus. I could swear it used to. I have to press "tab" once to set focus there, whereas previously it had the black rectangle right after inserting. Any thoughts?

Otherwise seems to work great! 👍 👍

@youknowriad youknowriad force-pushed the fix/black-border-appearing-too-often branch from 118de61 to 2f6b960 Compare February 20, 2018 08:14
@youknowriad
Copy link
Contributor Author

@jasmussen It should be happening in master too but I fixed it in this PR :)

@jasmussen
Copy link
Contributor

Confirmed! You fixed it! Nice work. Unless someone objects to the code, which I don't, then ship it!

@@ -187,6 +193,14 @@ export class BlockListBlock extends Component {
document.removeEventListener( 'mousemove', this.stopTypingOnMouseMove );
}

updateHasEditableContent() {
// Update the hasEditableContent property
const hasEditableContent = some( focus.tabbable.find( this.node ), isEditableNode );
Copy link
Member

@aduth aduth Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite concerned that we query select and filter on every change to the block. If it's a matter of avoiding effects that only appear on focusing a specific element (.editor-block-list__block-edit), could we do it on that element's focus event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could work, but the behavior of the block could change if its content change as well Imagine an image transformed to a text somehow or I don't know, blocks can do what they want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the absolute worst case I'd still prefer a MutationObserver monitoring childList and attributes. I expect at least this wouldn't fire the callback on every keypress.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated using a MutationObserver. Let me know what you think. In my testing, it doesn't trigger on each keypress.

@youknowriad youknowriad force-pushed the fix/black-border-appearing-too-often branch from 5b350a1 to d040066 Compare February 26, 2018 13:48
@aduth
Copy link
Member

aduth commented Feb 26, 2018

What are the steps to reproduce the original issue? Edit: Ok, I overlooked the steps from the original comment. All the same, couldn't focusTabbable on the block's own focus event handle this? Can you produce a failing case where this would not work per #5140 (comment) ?

I feel like we're going about this wrong. I don't understand why the block would be receiving focus in the first place, and if it's expected that it should, maybe we ought to be transitioning focus into the editable via BlockListBlock's focusTabbable. But I don't think it's expected that it should.

For what it's worth, I was able to reproduce this with nested blocks, but the behavior itself is buggy and not in a way that's remedied by the changes here, but rather symptomatic of a bigger problem.

  1. Create Columns block
  2. Add some text to one column
  3. Press Down
  4. First block in column will receive focus / black border

@jasmussen
Copy link
Contributor

Just in case there's doubt. The purpose of this is to indicate what has focus when the block outlines themselves have faded out because we're in isEditing mode.

For example, if you type /image and press Enter, block outlines (the 1px gray border and block controls) are faded out. Instead you should have a black rectangle around the placeholder, indicating that if you tab, you enter the buttons inside the placeholder.

@youknowriad
Copy link
Contributor Author

This is not only intended to fix the issues with keyboard navigation which could be considered as buggy anyway, but this fixes the black border issue more broadly as it's only intended for non-textual blocks, this makes it clearer with the code.

It's easy to recreate the same issue in master with only just clicks:

  • Insert a columns block
  • Click on the surroundings of the inner blocks => black border
  • Click on the surroundings of the columns block => black border.

We could consider fixing this issue by moving the focus to the inner tabbable each time the block wrapper receives the focus. I don't know if we want this though and also the block wrapper theoritically has tabIndex="0" so I'm wondering if this tabIndex make sense for these textual blocks? Another way to fix this issue is to remove the tabIndex if the block is textual.

@youknowriad
Copy link
Contributor Author

I'm closing this PR, as no consensus on the approach here. Fine to revisit later.

@youknowriad youknowriad closed this Mar 6, 2018
@youknowriad youknowriad deleted the fix/black-border-appearing-too-often branch March 6, 2018 17:26
@jasmussen
Copy link
Contributor

Okay to close this, but then I have to open a separate issue for #5140 (comment), as we need that addressed. But perhaps that's best done separately regardless — it seems like in the past focus was set on the block placeholder when using the slash command to insert, now it's set on the first button inside. I used to think this was desirable behavior, but it falls apart when blocks, and especially placeholder blocks get more complex.

@aduth
Copy link
Member

aduth commented Mar 6, 2018

Notice that as soon as I insert a placeholder using the slash command, the placeholder itself doesn't have focus. I could swear it used to. I have to press "tab" once to set focus there, whereas previously it had the black rectangle right after inserting. Any thoughts?

In my testing, after selecting from the autocomplete, the "Upload" button is focused.

This is indeed different than how it used to be, a noted change in behavior resulting from #5102 (specifically remarked at #5102 (comment) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants