-
Notifications
You must be signed in to change notification settings - Fork 7
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
Added keyboard text selection support #118
Merged
rsimon
merged 83 commits into
recogito:main
from
oleksandr-danylchenko:keyboard-event-selection
Sep 30, 2024
Merged
Added keyboard text selection support #118
rsimon
merged 83 commits into
recogito:main
from
oleksandr-danylchenko:keyboard-event-selection
Sep 30, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comment on lines
+11
to
+12
export const clonePointerEvent = (event: PointerEvent): PointerEvent => ({ | ||
...event, |
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.
Even though spreading event
returns only the { isTrusted }
object - it tricks the Typescript into thinking that the "cloned event" has the PointerEvent
type
rsimon
reviewed
Jul 12, 2024
This was referenced Jul 12, 2024
oleksandr-danylchenko
force-pushed
the
keyboard-event-selection
branch
from
July 18, 2024 08:29
e7d906f
to
11aae73
Compare
# Conflicts: # packages/text-annotator/src/TextAnnotator.css
oleksandr-danylchenko
force-pushed
the
keyboard-event-selection
branch
from
July 23, 2024 16:30
3d76e2b
to
ae27926
Compare
oleksandr-danylchenko
referenced
this pull request
in oleksandr-danylchenko/text-annotator-js
Jul 30, 2024
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # packages/text-annotator/src/SelectionHandler.ts
…nge-click' into keyboard-event-selection # Conflicts: # packages/text-annotator/src/SelectionHandler.ts
# Conflicts: # packages/text-annotator/src/SelectionHandler.ts
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup.tsx # packages/text-annotator/src/SelectionHandler.ts
…ent-selection # Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup.tsx # packages/text-annotator-react/test/App.tsx # packages/text-annotator-react/test/index.html # packages/text-annotator-react/test/tei/index.html
…nge-click' into keyboard-event-selection # Conflicts: # packages/text-annotator/src/SelectionHandler.ts
# Conflicts: # packages/text-annotator/src/SelectionHandler.ts
# Conflicts: # packages/text-annotator/src/SelectionHandler.ts # packages/text-annotator/src/TextAnnotator.ts
# Conflicts: # packages/text-annotator-react/test/App.tsx
…ick' into keyboard-event-selection # Conflicts: # packages/text-annotator/src/SelectionHandler.ts
# Conflicts: # packages/text-annotator-react/src/TextAnnotatorPopup.tsx # packages/text-annotator/src/SelectionHandler.ts
…ick' into keyboard-event-selection
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Previously, only the pointer-based selection was captured and processed by the
SelectionHandler
and the relatedTextAnnotatorPopup
. When the user initiated the selection with theShift + Arrow
orCtrl + A
- it wasn't represented in the annotation selection state. Therefore, we couldn't know when or whether the annotation popup should appear.Instead, for better a11y support, the selection should be able to start and conclude using exclusively keyboard events. The ability to start the selection anywhere on the page is already provided by the caret browsing mode.
Recommendations
Per a11y expert on our team, we received the following recommendations for the selection behavior:
Also, there were some recommendations on when the popup should be closed:
Relations
event
generalization annotorious/annotorious#420, which generalizes the user's selection event capturing.container
(vol.2) #149, which fixed reading obsoleteisCollapsed
value when processingpointerup
event.SelectionState
type to allow custom selection implementations annotorious/annotorious#419 (comment)Ctrl + A
doesn't make the annotation popup to appear #111Changes Made
lastPointerDown
to just thelastDownEvent
event, which preserves both thepointerdown
andkeydown
events. Both can be used to create the annotation selection state within theonSelectionChange
callback.TextAnnotatorPopup
component using theFloatingFocusManager
. Per @rsimon request, the automatic focus shift was tuned separately for the mouse and keyboard selection.For the mouse - the focus automatically goes to the first tabbable element within the floating to reduce the number of clicks required to jot down a note quickly.
For the keyboard - the focus gets shifted to the floating only when a user explicitly presses the
Tab
key. That allows us to make pauses during the selection and not lose the selection range before moving the popup.PointerSelectAction
withUserSelectAction
in re-exports and throughout the code.Demo
Mouse selection
mouse_selection.mov
Keyboard selection
keyboard_selection_arrow.mov
Esc
keypresskeyboard_selection_esc.mov
keyboard_selectino_close_button.mov
Screen.Recording.2024-08-21.at.19.47.15.mov