-
Notifications
You must be signed in to change notification settings - Fork 58
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
Moving the current block down sets the caret on the wrong block #311
Comments
Hey @Tug, would you mind to take a look at this issue here? It seems to be related to a wrong selected block index stored in props Added a log right before the action that does move the block, and the index of the selected block it seems "behind" by one step of the actual position of the just moved block.
|
Spent some time investigating this and even though I could see some unexpected store modifications at first, I'm now unable to reproduce now even after reverting my changes... |
Well, the issue does happen when you move down the block @Tug . Just re-tested |
Oh interesting, I haven't seen this behavior! |
I also tested on iOS simulator and the behavior is slightly different...sometime the caret is visible on the top block, and sometime it's not. This is definitely a sign that something under the hood is not working as expected. |
I've investigated this a bit more, and it seems - like @Tug mentioned above - that the problem on real devices is less noticeable than on emulators. I guess the caret is still available on emulators since the system sees an external keyboard attached to the device. Recapping (as of today):
Moving this ticket out of alpha. |
Maybe we still need this fixed in the Alpha since we're focusing on the writing flow? Can you elaborate on move to Beta @daniloercoli? Thanks! |
We'll want to fix this one soon, but losing focus when reordering blocks seem minor for the alpha. If it happened while splitting a block on enter, for instance, it would be more disruptive, but I see reordering blocks as a different mode than writing, so losing focus isn't that big of a deal. |
👋 @youknowriad , is that by design perhaps on Gutenberg-web? #311 (comment) |
Can we test this again? It'd be fine to leave out for the beta as long as the caret disappears when focus is lost. |
@hypest I don't think that's by design, when clicking buttons in browsers, the behavior can be different: in some browsers the button receives the focus, in others it doesn't. I feel like the best behavior would be to keep the caret at the same position but I'm not sure what a11y implications this could have. |
Thanks @youknowriad! Slightly confused by the "same position" though: do you mean same as in stick with the moving block so caret follows the block as it moves? Or "same" as in the caret stays at the (block) list index it was and doesn't follow the moving block? |
I was thinking if the block being moved is the selected block, just keep the caret at the same position in this block (the block moves obviously). I'd defer to the designers though for a better input on the expect behavior @mapk @jasmussen. |
This is a really good question. The problem here is that the caret position is tied to focus. Which means when you click the "move down" button, or even tab there and press Space, you move focus from where it was in text, to the block mover button. This would likely also explain why the soft keyboard closes when the mover is being used, because text no longer has focus. I don't know that this is an ideal situation, so I hesitate to say it's by design. But we have to be extremely careful to mess with what actually has focus, because I might want to use the tab key to set focus on the up mover, then press Space a bunch of times to move that block way to the top. So we can't just store the caret position and move focus back there as soon as you've moved a block. Can we do this? Desktop: store the caret position if you move the selected block, and if you start typing again, or use the arrow keys, we restore focus and the caret position first. Mobile: Don't close the soft keyboard if it was open and the block mover was used, and if user starts typing again, restore focus and caret position. Specifically #311 (comment) looks buggy — in that GIF, the block mover should have focus, but suddenly there's a caret in the Heading block above instead. Is any focus handling going on here? |
Let's completely remove the caret and focus from the editing component itself, since the user just tapped on the arrow button itself. We can revisit if the end results still feels wrong. cc @daniloercoli as you're currently assigned with the ticket. |
The problem reported here is also available in other testing scenario. See the video here: https://cloudup.com/cLtbRC7sr9l To reproduce:
It seems that on Android when there are EditText(s) on the screen, one of those needs to have the focus/show the caret. Back to the original testing steps:
I was able although to hide the keyboard when the block is moved down, that is just a small step forward, but makes the UI flow way better. |
#802 is merged and it does help on mitigating this problem, since it added the code that closes the keyboard when a block is moved Up/Down and making the writing flow a bit better. |
@jasmussen This makes sense, but it's also specific to the implementation of focus on the web. Both iOS and Android will keep the keyboard focus separate from the accessibility focus when VoiceOver/Talkback are enabled: I went to test some things on the web (using latest Safari) and now I'm more confused 😂 In a paragraph block, I can click on the block menu and the cursor is still visible and typing continues writing on the paragraph. From this I assume that a click event doesn't immediately take focus away from where the cursor is. I can navigate with tabs to different formatting buttons and apply styles. The selection and cursor are not visible while doing so, but the cursor is in the right position if I tab my way back to the block and start typing. This makes me think that preserving cursor position is doable, although it might be complicated. |
Moving this to future, since the current behavior seems good enough for 2.0 |
Moving a block down would move the focus on the wrong block.
This is only happening on Android, I̶ ̶t̶e̶s̶t̶e̶d̶ ̶i̶O̶S̶ ̶a̶n̶d̶ ̶i̶t̶ ̶s̶e̶e̶m̶s̶ ̶t̶o̶ ̶w̶o̶r̶k̶ ̶j̶u̶s̶t̶ ̶f̶i̶n̶e̶. The focus is kept on the current block, the one I just moved down.
Steps to repro:
Hello World
Welcome to GB
With the same steps above try to move the
code
block. The focus is moved to the first RichText block above.Note: I also see a warning in the AS log:
The text was updated successfully, but these errors were encountered: