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

Highlighter: Fix hinting state for keyboard-based selection #1691

Merged
merged 14 commits into from
Jul 31, 2024
Merged

Conversation

omnibs
Copy link
Member

@omnibs omnibs commented Jul 30, 2024

🔧 Modifying a component

Context

TL;DR: Shift+arrow now only apply the highlight when shift is released. "Hinting" mode is used while shift is pressed.

The way Highlighter keyboard-based selection worked made it very difficult to implement annotation functionality for writing.

Successive focus messages after each shift+arrow would throw a wrench on our code, and immediate creation of highlights would force us create+expand+expand+expand highlights, which would generate backend messages on each cycle.

Making kb-based selection work like the mouse, using hinting first, then applying marks to hinted segments all at once, when shift is released, is an elegant solution that not only completely solves our problems at the writing annotations side, but also opens the door to add friendlier screenreader cues to hinting state.

Specific things I want feedback on: Is the hinting screenreader cue ok?

🖼️ What does this change look like?

highlighter-new-msg.mov

Component completion checklist

  • I've gone through the relevant sections of the Development Accessibility guide with the changes I made to this component in mind
  • Changes are clearly documented
    • Component docs include a changelog
    • [ x Any new exposed functions or properties have docs
  • Changes extend to the Component Catalog
    • The Component Catalog is updated to use the newest version, if appropriate
    • The Component Catalog example version number is updated, if appropriate
    • Any new customizations are available from the Component Catalog
    • The component example still has:
      • an accurate preview
      • valid sample code
      • correct keyboard behavior
      • correct and comprehensive guidance around how to use the component
  • Changes to the component are tested/the new version of the component is tested
  • Component API follows standard patterns in noredink-ui
    • e.g., as a dev, I can conveniently add an nriDescription
    • and adding a new feature to the component will not require major API changes to the component
  • If this is a new major version of the component, our team has stories created to upgrade all instances of the old component. Here are links to the stories:
    • add your story links here OR just write this is not a new major version
  • Please assign the following reviewers:
    • Someone from your team who can review your PR in full and review requirements from your team's perspective.
    • Component library owner - Someone from this group will review your PR for accessibility and adherence to component library foundations.
    • If there are user-facing changes, a designer. (You may want to direct your designer to the deploy preview for easy review):
      • For writing-related component changes, add Stacey (staceyadams)
      • For quiz engine-related components, add Ravi (ravi-morbia)
      • For a11y-related changes to general components, add Ben (bendansby)
      • For general component-related changes or if you’re not sure about something, add the Design group (NoRedInk/design)

omnibs added 4 commits July 29, 2024 21:23
Before this change, keyboard-based selection would happen a segments at
a time, generating a marked segment and triggering focus at each step.

Now we're using hinting state, just like the mouse, until shift is
released, and only then adding the mark to the hinted segments.

This unbreaks NRI writing annotation functionality, and allows us to
have specific ScreenReader cues for hinting.
WCAG asks for only single-key actions to be undoable, but this is such
low effort
Copy link

linear bot commented Jul 30, 2024

@omnibs omnibs marked this pull request as ready for review July 30, 2024 03:22
Copy link
Contributor

@brian-carroll brian-carroll left a comment

Choose a reason for hiding this comment

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

Looks good! Couple of suggestions, nothing important. I'll leave it to Charbel or Ben to approve.

@@ -570,6 +572,16 @@ performAction action ( model, cmds ) =
( { model | selectionStartIndex = Nothing, selectionEndIndex = Nothing }, cmds )


isFirstLastHinted : Maybe ( Int, Int ) -> Highlightable marker -> Bool
isFirstLastHinted hintingIndices { index } =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
isFirstLastHinted hintingIndices { index } =
isFirstOrLastHinted hintingIndices { index } =

This is the first thing I see in the file so when I read it, I have no context to know whether "and" or "or" makes sense. Nice to have it in the name.

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

, Key.shiftLeft (Keyboard <| SelectionApplyTool highlightable.index)
, Key.shift (Keyboard <| SelectionReset highlightable.index)
[ -- Key.shift doesn't work on keyUp, bc `shiftKey` is False on keyUp
{ keyCode = 16
Copy link
Contributor

Choose a reason for hiding this comment

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

What does keyCode 16 mean? Is it the shift key itself? Or is it the case that the shift key doesn't have its own code and is only represented by the shiftKey field?

My guess is that it is represented in both fields and that 16 is the shift key. It's a while since I dealt with keypresses. I have not looked inside the Key lib, I could probably work it out if I did! I assume the Key.shift you mention is a named value you could import instead of hardcoding 16 but it is a record with shiftKey=True? If that's the case, maybe it could be written as shift.keyCode instead of 16, or { shift | shiftKey = False } or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh good call on doing shift.keyCode. { shift | shiftKey = False} would require a let assignment bc it's a function that takes a parameter. shift.keyCode is neater, then.

Yep 16 is the keycode for shift.

The shiftKey field indicates whether shift was held during the event, so you can disambiguate cases like this, where there's no unique keycode for a shifted right arrow, like there probably are for uppercase letters.

For the weird behavior that forces us to do this, I can guess w3c thought "when you release shift you're not holding shift amirite, so shiftKey gotta be false on keyup but true on keydown."

Copy link
Member Author

Choose a reason for hiding this comment

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

can't shift.keyCode bc it needs a parameter, so i did a small compromise. pushed it!

Co-authored-by: Brian Carroll <[email protected]>
@bendansby
Copy link
Contributor

"Selecting comment 9" means you are in the midst of highlighting text to make a comment, of which this will be the 9th of the assignment (or sequentially, the 9th in order)?

@omnibs
Copy link
Member Author

omnibs commented Jul 30, 2024

@bendansby yes!

@omnibs
Copy link
Member Author

omnibs commented Jul 30, 2024

on the numbering, the number is up to the use-case.

quizzes will use real names like "selecting evidence", writing is using weird numbers rn but we have an issue to fix it

@bendansby
Copy link
Contributor

Technically speaking, one is not selecting a comment, but selecting text to make a comment. Selecting a comment would be a different action. But perhaps the intention is to abbreviate a complex phrase into something simple? What do you think?

@omnibs
Copy link
Member Author

omnibs commented Jul 30, 2024

"Selecting text for [highlight-name]" is not terribly longer. Do you think it's clearer / less confusing?

@bendansby
Copy link
Contributor

I do! If you agree, let's go with that.

@omnibs
Copy link
Member Author

omnibs commented Jul 30, 2024

updated the video w/ the new msg, pushed addressing all review feedback so far =]

@omnibs omnibs requested a review from brian-carroll July 30, 2024 14:27
Copy link
Contributor

@charbelrami charbelrami left a comment

Choose a reason for hiding this comment

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

Looks great to me! Thanks for improving accessibility!

@omnibs omnibs added this pull request to the merge queue Jul 31, 2024
Merged via the queue into master with commit 4ba2dee Jul 31, 2024
8 checks passed
@omnibs omnibs deleted the phx-1772 branch July 31, 2024 02:44
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