-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
WIP: Try vertical arrow key navigation in WritingFlow #17084
Conversation
e2d0e66
to
90b2818
Compare
} | ||
|
||
const element = document.elementFromPoint( xPosition, yPosition ); | ||
if ( element && isTabbableTextField( element ) ) { |
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.
This works ok for now, but would fail if the element at the point was some formatting. A solution would be to check parent elements as well.
There is also elementsFromPoint
, which although marked on MDN as experimental, seems to be pretty widely supported:
https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementsFromPoint
@ellatrix This is a very early attempt at what we discussed in https://github.com/WordPress/gutenberg/pull/16957—vertical keyboard nav based on element screen positioning. It seems to work ok so far. I'm not sure how I'd handle something like |
I thought of a drawback of this approach—there'll be issues with some elements like toolbars covering nearby inputs. Ideally there would be a way to filter out those elements from the search for a tabbable element. |
This should not happen with |
502e4a2
to
d15949d
Compare
I've switched to using This does seem to work pretty well in my testing so far. Not sure if there are any additional things I need to think about. Potentially I should constrain the functionality to the bounds of the WritingFlow container. Another feature that I'm thinking about implementing is the use of Cmd/Ctrl with arrow keys keys to move straight to a table or grid's boundaries (as I had in my table block PR #16957). I think that could be considered on a separate PR and work on this incrementally. |
Ah, I've realised this little experiment of using |
Have you had a look at how we approach this vertically? I believe we try to scroll, then look again etc., but I'd have to check. Ideally the implementation is very similar so logic can be reused. This can be found in the DOM package. Otherwise I think the work done here is very promising! Would it be possible to write some e2e test, similar to the ones we have for vertical navigation? |
…hen a vertical arrow key is pressed
8e2faca
to
bfe2233
Compare
@ellatrix I've taken a different approach now, selecting the tabbable that's closest in distance. It seems to work better than before, and I don't have to worry if the element is off-screen. I need to consider how it'll work when navigating between blocks, but so far so good. I'll have a look at writing some e2e tests. |
Superceded by #22105 |
Description
Iteration on #16957, which attempts to bring vertical arrow key navigation to the
WritingFlow
component.When an up/down arrow key is pressed searches in the relevant direction from the caret until a tabbable text field is found. If none is found, tries searching from the right and left of the caret upwards or downwards until a tabbable is found.
How has this been tested?
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: