Problem/Motivation

When you use 'announce' => '' option, passed to MessageCommand ajax command, it's not supposed to announce the message, and while it doesn't announce the substance of the message, it does announce 'Warning message'.

Video: This video doesn't have audio, but you can see the messages from VoiceOver in the modal with a black background and white text. This video was made testing in Safari with VoiceOver.
https://www.drupal.org/files/issues/2019-10-24/no-announce-announcing.mov

Screenshot from the video:
No announce announcing

Proposed resolution

role='alert' shouldn't be added to error and warning messages if options.announce is an empty string.

Remaining tasks

review/commit.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

oknate created an issue. See original summary.

oknate’s picture

Title: MessageCommand with no announce option announce message type » MessageCommand with no announce option announces message type
oknate’s picture

Issue summary: View changes
StatusFileSize
new2.76 MB
oknate’s picture

Issue summary: View changes
StatusFileSize
new412.77 KB
oknate’s picture

Issue tags: +Accessibility
andrewmacpherson’s picture

Nice catch. Silent movies with the VoiceOver caption window are good.

oknate’s picture

Issue summary: View changes

Thanks!

Note, I'm not sure if this is a bug with MessageCommand, or Drupal.announce yet. I'll investigate.

oknate’s picture

Status: Active » Needs review
StatusFileSize
new2.64 KB

Here's a patch for this. It requires manual testing.

Testing instructions:

  1. Copy /core/modules/system/tests/modules/ajax_test to /modules/
  2. Enable the 'AJAX Test' module.
  3. Log in as user 1, go to ajax-test/message
  4. Enable VoiceOver on your mac
  5. Verify the "Make warning message" button does not announce "Warning message" after pressing it.
oknate’s picture

Issue summary: View changes
bnjmnm’s picture

  1. From #8

    Copy /core/modules/system/tests/modules/ajax_test to /modules/

    I am pleased to be able to mention that it is possible to run test modules without copying them to another directory. Add $settings['extension_discovery_scan_tests'] = TRUE; to settings.php.

  2. Create a failing test-only patch that expands MessageCommandTest to confirm the message wrapper doesn't have a role attribute is empty when MessageCommand with 'announce' => '' is executed, and of course add that test to the main patch as well.
  3. +++ b/core/misc/message.es6.js
    @@ -231,19 +231,23 @@
    +    if (announce !== '') {
    +      messageWrapper.setAttribute(
    +        'role',
    +        type === 'error' || type === 'warning' ? 'alert' : 'status',
    +      );
    +    }
    

    Provide a comment explaining why the role isn't set on an empty string (this can be deduced from the param description, but would be good to have here to mitigate future dev confusion)

While testing this I also noticed that most messages are read twice because they are sent to announce via add(), after which they are added to an element with an ARIA role defined. This usually doesn't happen with 'alert' as the alert kicks out the other attempt to announce the message, but I can make those occur twice in some instances with a throttled network connection. This will need a followup issue.

oknate’s picture

StatusFileSize
new3.09 KB
new6.4 KB

Addressing #10
1. Thanks! I'll remember that.
2. ✅Added test coverage and FAIL patch.
4. ✅Added comment explaining why we're removing role when announce set to an empty string.

Also, I added a follow-up for the duplicate reading: #3090371: Drupal.Message.add passing messages to Drupal.announce is usually redundant

The last submitted patch, 11: 3089888-11--FAIL.patch, failed testing. View results

bnjmnm’s picture

+++ b/core/misc/message.es6.js
@@ -231,19 +231,34 @@
+    // still be read when the element is added to the page.  To prevent that

Ubernit: there should only be one space separating the sentences.

Other than that, I think the changes are good. I added the tag "needs subsystem maintainer" since this modifies Drupal.message a bit. Not sure which jurisdiction this is, but I know @lauriii was active in the initial development of the JS messages API.

oknate’s picture

StatusFileSize
new860 bytes
new6.4 KB

Fixing nit in #13 about two spaces between sentences in the comment.

john cook’s picture

Status: Needs review » Needs work
StatusFileSize
new300.58 KB

I've tried to test this manually.

There are some extra buttons in the video that aren't in the test module. May be the extra buttons need to be added as well?

Clicking the "Make Warning Message" button still announces "Warning message I am a warning message in the default location." From the description and test instructions from comment #8, I don't think that this is intended

Setting back to needs work.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.