Skip to content

Commit

Permalink
Merge pull request #15294 from craftcms/feature/pt-72-notification-he…
Browse files Browse the repository at this point in the history
…ading-is-present-on-page-even-when-no

Hides SR-only notification heading when there are no active notifications
  • Loading branch information
brandonkelly authored Jul 4, 2024
2 parents c2cfd53 + 590b9c0 commit d473690
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Accessibility
- Improved the accessibility of two-step verification setup. ([#15229](https://github.com/craftcms/cms/pull/15229))
- The notification heading is no longer read to screen readers when no notifications are active. ([#15294](https://github.com/craftcms/cms/pull/15294))

### Administration
- Icon fields now have an “Include Pro icons” setting, which determines whether Font Awesome Pro icon should be selectable. ([#15242](https://github.com/craftcms/cms/issues/15242))
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_layouts/components/notifications.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="notifications" role="status">
<h2 id="cp-notification-heading" class="visually-hidden">{{ 'Notifications'|t('app') }}</h2>
<h2 id="cp-notification-heading" class="visually-hidden hidden">{{ 'Notifications'|t('app') }}</h2>
</div>

{% for type in ['notice', 'success', 'error'] %}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/web/assets/cp/src/js/CP.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Craft.CP = Garnish.Base.extend(
$crumbMenuList: null,
$crumbMenuItems: null,
$notificationContainer: null,
$notificationHeading: null,
$main: null,
$primaryForm: null,
$headerContainer: null,
Expand Down Expand Up @@ -85,6 +86,7 @@ Craft.CP = Garnish.Base.extend(
this.$crumbList = $('#crumb-list');
this.$crumbItems = this.$crumbList.children('li');
this.$notificationContainer = $('#notifications');
this.$notificationHeading = $('#cp-notification-heading');
this.$main = $('#main');
this.$primaryForm = $('#main-form');
this.$headerContainer = $('#header-container');
Expand Down Expand Up @@ -357,6 +359,11 @@ Craft.CP = Garnish.Base.extend(

// Load any element thumbs
this.elementThumbLoader.load(this.$pageContainer);

// Add notification close listeners
this.on('notificationClose', () => {
this._updateNotificationHeadingDisplay();
});
},

get $contentHeader() {
Expand All @@ -380,6 +387,10 @@ Craft.CP = Garnish.Base.extend(
.prependTo(this.$contentHeader);
},

get notificationCount() {
return this.$notificationContainer.find('.notification').length;
},

initSpecialForms: function () {
// Look for forms that we should watch for changes on
this.$confirmUnloadForms = $('form[data-confirm-unload]');
Expand Down Expand Up @@ -875,6 +886,17 @@ Craft.CP = Garnish.Base.extend(
}
},

/**
* Updates display property of "Notifications" heading based on whether there are active notifications
**/
updateNotificationHeadingDisplay() {
if (this.notificationCount > 0) {
this.$notificationHeading.removeClass('hidden');
} else {
this.$notificationHeading.addClass('hidden');
}
},

_setFixedTopPos: function ($element, headerHeight) {
if (!$element.length || !this.$contentContainer.length) {
return;
Expand Down Expand Up @@ -919,6 +941,8 @@ Craft.CP = Garnish.Base.extend(
notification,
});

this._updateNotificationHeadingDisplay();

return notification;
},

Expand Down Expand Up @@ -1817,6 +1841,7 @@ Craft.CP.Notification = Garnish.Base.extend({
duration: 'fast',
complete: () => {
this.destroy();
Craft.cp.trigger('notificationClose');
},
}
);
Expand Down

0 comments on commit d473690

Please sign in to comment.