Issue #3532958: Display a "No results found" message in the Admin Toolbar Search when no menu link matches

https://www.drupal.org/project/admin_toolbar/issues/3532958

Problem

When the search in the toolbar finds no match, nothing happens: the suggestion list simply stays hidden, so there is no evidence that a search was performed. Users cannot tell whether there are no results or whether the search is broken.

An earlier MR (!164 (closed)) was outdated after the refactoring of admin_toolbar_search.js in the 3.6.x releases (vanilla JS, scoped lookups), so this MR reimplements the feature on the current code.

Changes

js/admin_toolbar_search.js

  • When no menu link matches the query, the autocomplete displays a single "No results found" suggestion (translatable with Drupal.t()), instead of an empty list.
  • This suggestion has no linkUrl, which is how it is recognized (no magic value):
    • It is rendered as plain text in a span, not as a link, with the CSS class admin-toolbar-search-autocomplete-empty.
    • Selecting it (click or Enter) does nothing: the select callback only navigates when the item has a linkUrl.
    • Moving the focus to it with the arrow keys does not replace the search query typed in the input field (focus callback).
  • Accessibility: jQuery UI announces the number of results in its live region, which would be "1 result is available" for the message. The messages.results option is overridden to announce "No results found" instead in that case (the default message is kept otherwise).

css/admin_toolbar_search.css

  • The "No results found" item is not highlighted when hovered or focused (so the dark text is not displayed on the active blue background) and uses the default cursor, since it is not clickable.

Tests

  • New AdminToolbarSearchNoResultsTest (FunctionalJavascript):
    • the message is displayed for a query matching no link, with no link in the list;
    • clicking it, or moving to it with the keyboard and pressing Enter, does not navigate and does not change the search query;
    • the links are displayed again, without the message, for a matching query. It fails without the change. Its sed line is added to .gitlab-ci.yml like the other tests.

Notes

  • No server-side change is needed: the message is translated in the browser.
  • The extra links of Admin Toolbar Tools are loaded asynchronously the first time the field is focused: a query typed before they arrive may show the message until the next keystroke. This is not changed here.

How to test

  1. Install Admin Toolbar with Admin Toolbar Search with this MR (optionally with Admin Toolbar Tools).
  2. In the toolbar, type a search matching no link, for example zzzqqq: "No results found" is displayed, not as a link.
  3. Click the message, or move to it with the arrow keys and press Enter: nothing happens and the search query is kept.
  4. Type a search matching links, for example basic: the links are displayed, without the message, and still work.
  5. Check the display in the toolbar field and in the search tab tray, on mobile and wide screens, and with a screen reader if possible.

Merge request reports

Loading
Loading