-
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
Blocks: Fix the black border appearing too often in blocks #5140
Conversation
This seems to work nice. However there appears to be a regression with this rectangle in general, perhaps unrelated to this PR: 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! 👍 👍 |
118de61
to
2f6b960
Compare
@jasmussen It should be happening in master too but I fixed it in this PR :) |
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 ); |
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 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?
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.
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.
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.
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.
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.
Updated using a MutationObserver. Let me know what you think. In my testing, it doesn't trigger on each keypress.
5b350a1
to
d040066
Compare
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 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.
|
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. |
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:
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 |
I'm closing this PR, as no consensus on the approach here. Fine to revisit later. |
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. |
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) ). |
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