Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hides SR-only notification heading when there are no active notifications #15294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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