Skip to content
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

fix(core/form/inputs): fix issue with tabbing to popover toolbar buttons in PT-input #5057

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

skogsmaskin
Copy link
Member

@skogsmaskin skogsmaskin commented Oct 24, 2023

Description

There is currently an issue with reaching the annotation and inline object edit toolbar buttons with the keyboard leaving annotation editing impossible with the keyboard.

This will make sure that when these toolbars shows, it will be possible to press Tab in order to get to the buttons with the keyboard.

keyboard.navigation.mov

Also added component tests for this.

What to review

That you are able to tab into the buttons when the toolbar is showing.

Notes for release

  • Fixed an issue with keyboard navigation to edit buttons for annotation and inline objects in the Portable Text Input.

@vercel
Copy link

vercel bot commented Oct 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 1:48pm
performance-studio ✅ Ready (Inspect) Visit Preview Jan 16, 2025 1:48pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 1:48pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 1:48pm
test-next-studio ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 1:48pm

@skogsmaskin skogsmaskin changed the title Fix/pt input tab to toolbar fix(core/form/inputs): fix issue with navigating to toolbar buttons with keyboard Oct 24, 2023
@skogsmaskin skogsmaskin changed the title fix(core/form/inputs): fix issue with navigating to toolbar buttons with keyboard fix(core/form/inputs): fix issue with tabbing to popover toolbar buttons in PT-input Oct 24, 2023
@github-actions
Copy link
Contributor

No changes to documentation

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2023

Component Testing Report Updated Jan 16, 2025 1:35 PM (UTC)

❌ Failed Tests (2) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 4s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ❌ Failed (Inspect) 1m 19s 5 0 1
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 51s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 15s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 27s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ❌ Failed (Inspect) 1m 47s 14 0 1
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 28s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 2m 0s 21 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 12s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 42s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

@robinpyon robinpyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @skogsmaskin, this is a huge improvement.

Just had a look and noticed a few things:

  1. When pressing TAB for the first time over an annotation, it will try focus the next element briefly before then focusing buttons within the popover.

If you look at this video and pay attention to the 'No items' box, you'll see what I mean:

Screenflick.Movie.30.mp4

I'm very certain this is the case due to buttonRef.current.focus() being wrapped within a setTimeout. This does seem like a bit of a smell!

One possible alternative is that rather than focusing the button directly, we create an invisible anchor element (with tabIndex=-1), and then on TAB:

  • initially focus the anchor element. Since it has tabIndex=-1, it will be ignored in sequential keyboard navigation
  • the browser will then 'naturally' tab to the next button in the list

Here's an example video with that approach:

Screenflick.Movie.31.mp4
  1. This popover doesn't trap focus – making it very easy to accidentally tab or shift-tab away completely out of the form. We should probably trap focus here.

  2. Focus isn't restored when closing the popover – ideally, closing the popover with ESC returns you exactly where you were.

We could probably punt on 2 + 3, but should capture these if we do.

@skogsmaskin skogsmaskin requested a review from a team December 18, 2023 18:19
@skogsmaskin skogsmaskin requested a review from a team as a code owner December 18, 2023 18:19
@skogsmaskin skogsmaskin requested review from ricokahler and removed request for a team December 18, 2023 18:19
@RitaDias
Copy link
Contributor

@skogsmaskin I'm assuming that this PR can be closed? 👀

@RitaDias RitaDias removed the request for review from a team June 27, 2024 06:15
@hermanwikner hermanwikner removed their request for review July 10, 2024 14:50
@skogsmaskin skogsmaskin force-pushed the fix/pt-input-tab-to-toolbar branch from 3de982b to 4987734 Compare January 2, 2025 12:47
@skogsmaskin
Copy link
Member Author

skogsmaskin commented Jan 2, 2025

In the following video, I tab into a PTE field and keep pressing tab. Currently, the user would be able to exit the PTE field by tabbing, but in this branch focus is trapped. Is that intentional?

Screen.Recording.2024-12-16.at.09.46.08.mov

It is intentional from my side yes, so that you get back to editor again (which is probably what you want in 99% of cases). Closing the popover (ESC) will break out from the focus trap and let you move focus with tab normally.

@bjoerge bjoerge force-pushed the fix/pt-input-tab-to-toolbar branch from 4987734 to 24e7206 Compare January 7, 2025 14:29
@skogsmaskin skogsmaskin force-pushed the fix/pt-input-tab-to-toolbar branch from 24e7206 to 50ded22 Compare January 16, 2025 13:04
@skogsmaskin skogsmaskin force-pushed the fix/pt-input-tab-to-toolbar branch from 50ded22 to 9c4e5ce Compare January 16, 2025 13:11
…able Text Input

This will allow a user to purely use the keyboard when editing links and inline objects,
which was not possible before.
@juice49
Copy link
Contributor

juice49 commented Jan 16, 2025

Okay, thanks for explaining! I just wanted to make sure it was on purposes. In that case, this looks good to me!

@skogsmaskin skogsmaskin added this pull request to the merge queue Jan 16, 2025
Merged via the queue into next with commit 6c61c9c Jan 16, 2025
58 checks passed
@skogsmaskin skogsmaskin deleted the fix/pt-input-tab-to-toolbar branch January 16, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants