Skip to content

Commit

Permalink
Merge pull request #15036 from primefaces/issue-14972
Browse files Browse the repository at this point in the history
Fixed #14972 - MenuBar | Remove duplicate id
  • Loading branch information
cetincakiroglu authored Mar 13, 2024
2 parents 6db60e7 + 75f48dc commit f68a502
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/app/components/menubar/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class MenubarService {
[attr.aria-label]="ariaLabel"
[attr.aria-labelledBy]="ariaLabelledBy"
(keydown)="menuKeydown.emit($event)"
[attr.id]="menuId"
[attr.id]="root ? menuId : null"
[attr.aria-activedescendant]="focusedItemId"
>
<ng-template ngFor let-processedItem [ngForOf]="items" let-index="index">
Expand Down Expand Up @@ -121,11 +121,11 @@ export class MenubarService {
[attr.tabindex]="-1"
>
</span>
<span *ngIf="getItemProp(processedItem, 'escape'); else htmlLabel" class="p-menuitem-text" [attr.data-pc-section]="'label'">
<span *ngIf="getItemProp(processedItem, 'escape'); else htmlLabel" class="p-menuitem-text" [attr.data-pc-section]="'label'" [id]="getItemLabelId(processedItem)">
{{ getItemLabel(processedItem) }}
</span>
<ng-template #htmlLabel>
<span class="p-menuitem-text" [innerHTML]="getItemLabel(processedItem)" [attr.data-pc-section]="'label'"></span>
<span class="p-menuitem-text" [innerHTML]="getItemLabel(processedItem)" [attr.data-pc-section]="'label'" [id]="getItemLabelId(processedItem)"></span>
</ng-template>
<span class="p-menuitem-badge" *ngIf="getItemProp(processedItem, 'badge')" [ngClass]="getItemProp(processedItem, 'badgeStyleClass')">{{ getItemProp(processedItem, 'badge') }}</span>
Expand Down Expand Up @@ -192,6 +192,7 @@ export class MenubarService {
[activeItemPath]="activeItemPath"
[focusedItemId]="focusedItemId"
[level]="level + 1"
[ariaLabelledBy]="getItemLabelId(processedItem)"
(itemClick)="itemClick.emit($event)"
(itemMouseEnter)="onItemMouseEnter($event)"
>
Expand Down Expand Up @@ -273,6 +274,10 @@ export class MenubarSub implements OnInit, OnDestroy {
return this.getItemId(processedItem);
}

getItemLabelId(processedItem: any): string {
return `${this.menuId}_${processedItem.key}_label`;
}

getItemClass(processedItem: any) {
return {
...this.getItemProp(processedItem, 'class'),
Expand Down

0 comments on commit f68a502

Please sign in to comment.