Skip to content

Fix keyboard shortcuts modal in super sidebar

Mark Florian requested to merge fix-keyboard-shortcuts-button into master

What does this MR do and why?

This fixes the keyboard shortcuts menu item in super sidebar. On certain pages (e.g., any project page, like a merge request or issues list), the button did nothing except log an error:

TypeError: t.toggleShortcutsHelp is not a function

The help button was added in !109385 (merged), but it wasn't working on certain pages, specifically those listed in ~/behaviors/shortcuts.js.

This removes the global function defined on pages other than those listed above. Instead, we now rely on event delegation in the Shortcuts class for detecting the clicks to the shortcuts modal trigger, since the sidebar might not be in the DOM by the time the Shortcuts constructor (or some subclass of it) is called.

Screenshots or screen recordings

n/a

How to set up and validate locally

  1. Enable the super_sidebar_nav feature flag
  2. Enable the new navigation user preference
  3. Visit any page listed in ~/behaviors/shortcuts.js#L4-24
  4. Click the Help > Keyboard shortcuts button in the sidebar
  5. Observe the shortcuts modal appears
  6. Repeat steps 2 to 4 inclusive for a page not listed above (e.g., the Explore dashboard, or To-Dos)
  7. Check all of the above still works when the new navigation user preference is disabled

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mark Florian

Merge request reports