Problem/Motivation
In #2995689: Allow reordering blocks without a pointer device. we have the need to call Drupal.announce() to inform screen reader users that block list has been updated. Currently this patch has no javascript changes.
We currently have \Drupal\Core\Ajax\AlertCommand
but no way to call Drupal.annouce()
directly via an Ajax response.
Proposed resolution
Create \Drupal\Core\Ajax\AnnouceCommand
that would call Drupal.announce()
This would make it easy to use Drupal.announce and encourage to its use when an ajax response should notify screen reader users of an update.
Remaining tasks
Create commandCreate tests- Manually test
To manually test:
- apply the patch
- enable the test module 'ajax_forms_test'.
- goto */ajax_forms_test_ajax_commands_form*
- click the button *AJAX 'Announce': Click to announce*
- Confirm the message appears in HTML
<div id="drupal-live-announce" class="visually-hidden" aria-live="polite" aria-busy="false">This is my announcement.</div>'
User interface changes
none
API changes
none
Data model changes
None
Release notes snippet
The new Ajax command AnnounceCommand is now available to trigger screen reader announcements directly in Ajax responses. This command can be added to a \Drupal\Core\Ajax\AjaxResponse object like any other command that implements \Drupal\Core\Ajax\CommandInterface. The announcements will be made via the Drupal.announce()
JavaScript method.