Skip to content

Commit

Permalink
Fixed double badge count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 3, 2024
1 parent 033ba99 commit 3008e3c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Fixed a bug where double-clicking on an element’s linked label or action button would cause its slideout to open, in addition to the link/button being activated. ([#14736](https://github.com/craftcms/cms/issues/14736))
- Fixed a bug where system icons whose names ended in numbers weren’t displaying. ([#14740](https://github.com/craftcms/cms/issues/14740))
- Fixed an error that could occur when creating a passkey. ([#14745](https://github.com/craftcms/cms/issues/14745))
- Fixed a bug where the “Utilities” global nav item could get two badge counts.

## 5.0.0 - 2024-03-26

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.

33 changes: 16 additions & 17 deletions src/web/assets/cp/src/js/CP.js
Original file line number Diff line number Diff line change
Expand Up @@ -1315,25 +1315,24 @@ Craft.CP = Garnish.Base.extend(
Craft.sendActionRequest('POST', 'app/get-utilities-badge-count')
.then(({data}) => {
// Get the existing utility nav badge and screen reader text, if any
let $badge = $utilitiesLink.children('.badge');
let $screenReaderText = $utilitiesLink.children(
let $badge = $utilitiesLink.children('.sidebar-action__badge');

if (data.badgeCount && !$badge.length) {
$badge = $(
'<span class="sidebar-action__badge">' +
'<span class="badge" aria-hidden="true"></span>' +
'<span class="visually-hidden" data-notification></span>' +
'</span>'
).appendTo($utilitiesLink);
}

const $badgeLabel = $badge.children('.badge');
const $screenReaderText = $badge.children(
'[data-notification]'
);

if (data.badgeCount) {
if (!$badge.length) {
$badge = $(
'<span class="badge" aria-hidden="true"/>'
).appendTo($utilitiesLink);
}

if (!$screenReaderText.length) {
$screenReaderText = $(
'<span class="visually-hidden" data-notification/>'
).appendTo($utilitiesLink);
}

$badge.text(data.badgeCount);
$badgeLabel.text(data.badgeCount);
$screenReaderText.text(
Craft.t(
'app',
Expand All @@ -1343,10 +1342,10 @@ Craft.CP = Garnish.Base.extend(
}
)
);
} else if ($badge.length && $screenReaderText.length) {
} else if ($badge.length) {
$badge.remove();
$screenReaderText.remove();
}

resolve();
})
.catch(reject);
Expand Down

0 comments on commit 3008e3c

Please sign in to comment.