Skip to content

Make icon buttons and menu toggles reachable and usable with the keyboard - #5683

Merged
freescout-help-desk merged 1 commit into
freescout-help-desk:masterfrom
JayOfTheKeyboard:fix/toolbar-keyboard-access
Sep 30, 2026
Merged

freescout-help-desk merged 1 commit into
freescout-help-desk:masterfrom
JayOfTheKeyboard:fix/toolbar-keyboard-access

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown
Contributor

Related: #1150

Problem

In the conversation view, most of the icon buttons can't be reached with Tab, and can't be pressed with Enter or Space. The toolbar icons are rendered as spans with role="button" and an aria-label, but no tabindex:

<span class="hidden-xs conv-delete conv-action glyphicon glyphicon-trash"
      data-toggle="tooltip" data-placement="bottom"
      title="Delete" aria-label="Delete"
      role="button"></span>

A span is not focusable by default, so Tab skips it. The markup says "button" to screen readers, but a keyboard user can't reach it or press it. Even with focus, Enter does nothing, because no key handler is attached. Only the click handler is.

The same applies to:

  • the toolbar: Reply, Note, Delete, More Actions (resources/views/conversations/view.blade.php)
  • the star next to the conversation number, and the star in each row of the conversation list (an <i> with a click handler, no role)
  • each thread's options menu, the caret at the top right of every message (resources/views/conversations/partials/thread.blade.php)
  • the mailbox and user sidebar menus on the settings pages (mailboxes/sidebar_menu.blade.php, users/sidebar_menu.blade.php)

To reproduce: open any conversation and press Tab repeatedly. After the mailbox menu, focus goes from "New Conversation" straight to the Assignee and Status buttons. Reply, Note, Delete and More Actions are skipped, and so is the star.

I noticed this while working through a backlog of emails from the keyboard. Every delete needs the mouse.

Fix

  1. Add tabindex="0" to those elements (and role="button" to the stars), so they join the Tab order where they sit on the page. The thread options and sidebar toggles get it under the same condition that renders their menu (isAdmin() for line-item threads, count($menu_mailboxes), count($users)), so there is no Tab stop that opens nothing.
  2. Add one delegated keydown handler in main.js, next to the other global handlers, which clicks a focused span/i with role="button" on Enter or Space, the way a native button behaves:
$(document).on('keydown', 'span[role="button"][tabindex], i[role="button"][tabindex]', function(e) {
    if ((e.which != 13 && e.which != 32) || (e.originalEvent && e.originalEvent.repeat)) {
        return;
    }
    if (e.which == 32 && $(this).is('[data-toggle="dropdown"]')) {
        return;
    }
    e.preventDefault();
    $(this).click();
});

Key repeat is ignored, so holding Enter on a star sends one request, not one per repeat. Space on a dropdown toggle is left alone, because Bootstrap's dropdown keydown handler already opens the menu on Space. Handling it here as well would open and immediately close it. Enter is not handled by Bootstrap, so it goes through .click() like the other elements, and then the arrow keys move through the menu as usual.

The selector only matches elements that have both role="button" and a tabindex, so nothing else on the page changes behaviour. Existing click handlers are reused, so each action does exactly what a mouse click does.

Element Before After
Reply, Note, Delete icons skipped by Tab reachable, Enter/Space activates
More Actions skipped by Tab reachable, Enter or Space opens, arrows move
Star (conversation and list) skipped by Tab reachable, Enter/Space toggles
Thread options caret skipped by Tab reachable, Enter or Space opens
Mailbox / user sidebar menu skipped by Tab reachable, Enter or Space opens
Mouse and touch unchanged unchanged

Not changed

  • The thread options caret has no accessible name (it contains only <b class="caret"></b>). A screen reader announces it as "button". An aria-label would need a string, so I left that for you to decide.
  • Buttons that modules add through @action('conversation.action_buttons') are not changed. If a module renders a span/i with role="button" and tabindex, it now also responds to Enter and Space. I found no such element in core.
  • The stars don't expose a pressed state (aria-pressed), and their title isn't updated after toggling. That is a screen-reader improvement beyond keyboard access, so I left it out.
  • No visual change: the browser's default focus outline shows on the focused icon, and style.css doesn't suppress it for these elements.

Tested

On master at 929c575, PHP 8.2, MariaDB 11, Chrome, with real key events (CDP Input.dispatchKeyEvent), not synthetic JS events:

  • Before: none of the elements above is ever reached by Tab.
  • After: each one is reached. Enter opens the Delete confirmation, Reply opens the editor, the star toggles, and More Actions, the thread menu and both sidebar menus open. Space opens More Actions once. Escape closes the confirmation, and the conversation is not deleted.
  • The star in the conversation list is reached and toggles. Holding Enter on it (auto-repeat key events) sends one star_conversation request.
  • As a non-admin user, the line-item thread toggle is not a Tab stop and the message thread toggle is.
  • Each part was also removed on its own to check the test catches it: without the keydown handler the Enter checks fail; without the Space exception More Actions opens and closes again on Space; without the repeat check a held Enter sends 4 star requests; without the isAdmin() condition the non-admin line-item toggle becomes an empty Tab stop.

Files

  • public/js/main.js: keydown handler
  • resources/views/conversations/view.blade.php: toolbar icons, More Actions, star
  • resources/views/conversations/conversations_table.blade.php: list stars (both occurrences)
  • resources/views/conversations/partials/thread.blade.php: thread options (both occurrences)
  • resources/views/mailboxes/sidebar_menu.blade.php, resources/views/users/sidebar_menu.blade.php: sidebar menus

…oard

The conversation toolbar icons (Reply, Note, Delete, More Actions), the star in the conversation and in the list, each thread's options menu and the mailbox and user sidebar menus are span/i elements with role="button" (or no role) and no tabindex, so Tab skips them and Enter or Space does nothing. Add tabindex="0" (only where the menu is rendered, so there are no empty Tab stops) and a delegated keydown handler that clicks role="button" spans and icons on Enter and Space, ignoring key repeat. Space on a dropdown toggle is left to Bootstrap, which already opens it.
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