lea11y logo, to start
  • Home
  • Keyboard navigation
  • JavaScript Overrides
  • Home
  • About
  • Fundamentals
  • Most common problems
  • Keyboard navigation
  • On ARIA
  • HTML
  • Glossary
  • Links

JavaScript Overrides

Content note

This content is unreviewed.

You can override some of the keyboard handling via JavaScript, but this comes with the risk of breaking accessibility for screenreader users.

Keyboard handling for canvas-based games

Browser-based games often override the arrow keys. One way is to add the event listeners on the window object. However, this will deactivate the cursors for everything else on the webpage.

Adding a tabindex="0" would mark the canvas as an interactive element and whenever it gets focused, it can receive keyboard events. This is the more accessible option to activate custom keyboard handling.

Custom keyboard shortcuts

Sometimes, it might make sense to provide a couple keyboard shortcuts. You can use the accesskey attribute on interactive elements to provide some shortcuts.

Some websites include a micro library called tiny-keys to integrate a quick search (command/control K) or command palette (command/control P).

But as always: be aware to test it with common screenreaders and browsers for conflicting keymappings.

In this chapter

  • Keyboard navigation
  • Focus
  • Testing Keyboard Accessibility
  • JavaScript Overrides
  • Browser Configuration

Made with 💖 love by Lea

  • Imprint
  • Accessibility statement
  • License
  • Privacy