Message JS theme function should allow additional CSS classes and HTML attributes to be added.

Created on 27 May 2025, about 2 months ago

Problem/Motivation

The message theme function (/core/misc/message.js) does not allow additional HTML attributes and CSS classes to be added. Additional HTML attributes such as aria-live may be needed for accessability reasons. Adding custom CSS classes may be needed to find DOM elements in JavaScript/AJAX or customize styling.

An example of this need is the managed file upload error message in: /core/modules/file/file.js

  $(this)
  .closest('div.js-form-managed-file')
  .prepend(
    `<div class="messages messages--error file-upload-js-error" aria-live="polite">${error}</div>`,
  );

To replace the hardcoded message markup with the message JS theme function it would require adding the aria-live="polite" attribute and the CSS class file-upload-js-error.

Steps to reproduce

N/A

Proposed resolution

Allow custom HTML attributes and CSS classes to be passed to the message JS theme function.

Remaining tasks

  1. Agree on solution.
  2. Implement solution.
  3. Write automated test to confirm functionality.
  4. Write release notes.

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

javascript

Created by

πŸ‡ΊπŸ‡ΈUnited States pcate

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024