gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Inconsistent keyboard behaviour in Search block

Open tellthemachines opened this issue 4 years ago • 3 comments

Description

When moving through the Search block with the arrow keys, focusing on the "Add label" field and then pressing Arrow Down takes us to the "Optional placeholder" field, and Arrow Down again takes us out of Search and into the next block. However, navigating back with Arrow Up key, the first field to receive focus in the Search block is the "Add button text" field, followed by the "Add label" field.

On the way down, "Add button text" is skipped. On the way up, "Optional placeholder" is skipped.

Focus order should be the same in both directions.

Step-by-step reproduction instructions

  1. In the block editor, add a Search block, followed by a paragraph or other block
  2. Starting with focus in the "Add label" field, move focus with Arrow Down until it leaves the Search block
  3. Move focus back into Search with Arrow Up
  4. Verify that focus order is different in both directions.

Screenshots, screen recording, code snippet

video recording

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

tellthemachines avatar Jan 27 '22 01:01 tellthemachines

@tellthemachines this seems to have been fixed (I guess in previous Gutenberg releases).

https://user-images.githubusercontent.com/33403964/167603941-4ea492e3-8efe-4981-bbf3-70be4b3818ce.mp4

JustinyAhin avatar May 10 '22 10:05 JustinyAhin

I can still reproduce it as of today in Gutenberg trunk:

https://github.com/user-attachments/assets/ad176cc1-1b31-49f9-9657-8b35a00394c2

tellthemachines avatar Aug 10 '26 05:08 tellthemachines

I looked into why the order differs by direction. In writing-flow/use-arrow-nav.js, getClosestTabbable() with onlyVertical only accepts fields that overlap the current field horizontally. In the Search block the "Optional placeholder text" input and the button sit side by side. Going down from the input skips the button. Going up from the block below lands on the button (last in DOM order), and going up from the button then skips the input.

Making both directions match would change shared writing-flow behaviour, for example how Up and Down move between Columns. Which should be the preferred one?

  • Make Up land on the field nearest the caret's horizontal position.
  • Let the Search block's button and input be reached one after the other by arrow keys.
  • Leave it as is, since arrow keys follow the layout.

00kaku avatar Oct 22 '26 04:10 00kaku