Skip to content

Move criterion keyboard navigation into React components#7989

Merged
david-yz-liu merged 7 commits into
masterfrom
criterion-navigation-keybindings
Jun 7, 2026
Merged

Move criterion keyboard navigation into React components#7989
david-yz-liu merged 7 commits into
masterfrom
criterion-navigation-keybindings

Conversation

@david-yz-liu
Copy link
Copy Markdown
Collaborator

@david-yz-liu david-yz-liu commented Jun 6, 2026

Proposed Changes

Moves the grading page keyboard navigation bindings out of the global keybinding.js jQuery-based handlers and into the React components that own the relevant state.

shift+up / shift+down (navigate between criteria) were previously implemented by exposing the entire MarksPanel class instance as window.marksPanel and calling methods on it from keybinding.js. The global is eliminated: MarksPanel now binds these keys directly in componentDidMount and unbinds them in componentWillUnmount.

up / down / enter (navigate rubric levels within a criterion) were previously implemented with jQuery DOM queries ($(".active-rubric")) that mutated CSS classes directly, bypassing React. RubricCriterionInput now tracks the highlighted level as hoveredLevelIndex state and binds the three keys via Mousetrap while the criterion is active (and unbinds them on deactivation or unmount).

Bug fixes: (1) shift+up / shift+down were silently suppressed whenever a flexible or checkbox criterion's <input> had focus, because Mousetrap blocks all keybindings on form elements by default. A targeted stopCallback override in keybinding.js now allows navigation combos. (2) Navigating between criteria now ensures the active criterion is scrolled into view.

Type of Change

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue) X
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

As a side effect, this work unblocks wrapping MarksPanel with React.memo in a future PR, which would prevent the entire marks panel from re-rendering when unrelated state (e.g. the annotation dialog) changes in the parent Result component.

david-yz-liu and others added 2 commits June 6, 2026 10:49
Shift+up/shift+down (criterion navigation) are now bound in MarksPanel's
componentDidMount, removing the window.marksPanel global. Up/down/enter
(rubric level navigation) are now bound in RubricCriterionInput via a
useEffect, replacing jQuery DOM class mutation with a hoveredLevelIndex
state value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mousetrap blocks all keybindings when a form input has focus. Override
stopCallback to allow navigation combos (shift+up/down/left/right,
ctrl+shift+right, alt+enter) through — these don't produce characters
so suppression was incorrect. shift+n remains blocked while typing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 6, 2026

Coverage Report for CI Build 27080148407

Coverage increased (+0.1%) to 90.304%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 65 of 65 lines across 5 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 50162
Covered Lines: 46268
Line Coverage: 92.24%
Relevant Branches: 2243
Covered Branches: 1056
Branch Coverage: 47.08%
Branches in Coverage %: Yes
Coverage Strength: 125.98 hits per line

💛 - Coveralls

david-yz-liu and others added 4 commits June 6, 2026 11:39
Mousetrap.init() creates an internal documentMousetrap instance and copies
forwarding wrappers onto the constructor. At event time, stopCallback is
resolved via prototype lookup on that instance, so patching the static
wrapper had no effect. Patch Mousetrap.prototype.stopCallback instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Each criterion component now holds a ref to its root <li> and calls
scrollIntoView({ block: "nearest", behavior: "smooth" }) when its active
prop becomes true, so keyboard navigation keeps the selected criterion
visible without scrolling unnecessarily when it is already on screen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…yDown

Replaces all Mousetrap.trigger() calls in marks_panel tests with
fireEvent.keyDown(), which fires real DOM events through Mousetrap's full
pipeline including stopCallback. Moves the Mousetrap.prototype.stopCallback
patch and a scrollIntoView stub into jest_after_env_setup.js so they apply
globally. Removes workaround optional chaining (?.scrollIntoView and
?.preventDefault) from application code now that tests exercise the real path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@david-yz-liu david-yz-liu force-pushed the criterion-navigation-keybindings branch from 37f1aa0 to 78dd85d Compare June 6, 2026 17:51
@david-yz-liu david-yz-liu merged commit c49f78c into master Jun 7, 2026
11 checks passed
@david-yz-liu david-yz-liu deleted the criterion-navigation-keybindings branch June 7, 2026 16:08
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.

2 participants