gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Arrow keys refocus the editor when pressing right/left on the alignment button

Open ephox-mogran opened this issue 9 years ago • 4 comments

Arrow navigation doesn't work in the toolbar for any button that isn't the block switcher.

Issue Overview

When focusing the toolbar, the first right arrow key moves successfully to alignment, but the second right arrow key moves focus back to the editor.

Steps to Reproduce (for bugs)

  1. Focus the toolbar in a paragraph block
  2. Press right once to move to alignment
  3. Press right again to move to the next alignment

Browser: Chrome

Expected Behavior

The next alignment button is highlighted

Current Behavior

The move jumps back to the editor

Possible Solution

My understanding:

This looks like it is caused by slots. The BlockSwitcher has a NavigableMenu component as an ancestor, and the rest of the toolbar is populated by slots. Although these slots are put in the same DOM position as the BlockSwitcher, they do not have the same react ancestry. Therefore, the key events are never handled by NavigableMenu.

This looks like it is supported by this react documentation: https://reactjs.org/docs/portals.html#event-bubbling-through-portals

My understanding of that is that even though we are rendering the formatting toolbar inside the toolbar, its actual react ancestry is where it is created which is in Editable. Therefore, NavigableMenu never gets reached.

Todos

  • [ ] Tests
  • [ ] Documentation

ephox-mogran avatar Oct 20 '17 05:10 ephox-mogran

My understanding of that is that even though we are rendering the formatting toolbar inside the toolbar, its actual react ancestry is where it is created which is in Editable. Therefore, NavigableMenu never gets reached.

True, I guess the solution would be to rewrite slot-fill to an implementation closer to what react-slot-fill does, storing the children of a fill in a variable and rendering them as children to the slot element.

Or make it opt-in/opt-out via a prop in the slot or fill component if the current behavior is desirable somewhere (which I don't think it's true at the moment). cc @aduth

youknowriad avatar Oct 20 '17 08:10 youknowriad

This can be considered fixed (temporarily) by #3083 ?

The portal implementation definitely introduced a different way for events to bubble. I could see both behaviors being desirable, since one might think that if FormatToolbar is rendered by Editable, then Editable should be able to capture bubbling events from it.

storing the children of a fill in a variable and rendering them as children to the slot element.

One of the main issues we'd need to address with the implementation is that rendering would occur out of order from what is expected since lifecycle changes to fills are only reflected after an internal call to setState. This worked much better with portals.

aduth avatar Oct 20 '17 12:10 aduth

#3083 has been merged, so @aduth should we close this issue? It looks like it is fixed now.

ephox-mogran avatar Oct 24 '17 03:10 ephox-mogran

Yeah, we can close. But I do want to plan to reintroduce the consistent slot fill implementation, which will require some thinking about what is the most sensible events bubbling behavior.

aduth avatar Oct 24 '17 15:10 aduth