Skip to content

Commit

Permalink
Merge pull request #17035 from primefaces/issue-16972
Browse files Browse the repository at this point in the history
Fixed #16972 | Panel: Panel Content focusable and announced by assist…
  • Loading branch information
mehmetcetin01140 authored Dec 12, 2024
2 parents 36ac7cd + 349e49c commit 06a4c28
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/primeng/src/panel/panel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { animate, state, style, transition, trigger } from '@angular/animations';
import { CommonModule } from '@angular/common';
import { booleanAttribute, ChangeDetectionStrategy, Component, ContentChild, EventEmitter, inject, Input, NgModule, Output, TemplateRef, ViewEncapsulation } from '@angular/core';
import { booleanAttribute, ChangeDetectionStrategy, Component, ContentChild, ElementRef, EventEmitter, inject, Input, NgModule, Output, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
import { uuid } from '@primeuix/utils';
import { BlockableUI, Footer, SharedModule } from 'primeng/api';
import { BaseComponent } from 'primeng/basecomponent';
Expand Down Expand Up @@ -139,7 +139,7 @@ export interface PanelHeaderIconsTemplateContext {
"
(@panelContent.done)="onToggleDone($event)"
>
<div class="p-panel-content">
<div class="p-panel-content" #contentWrapper>
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
Expand Down Expand Up @@ -315,6 +315,8 @@ export class Panel extends BaseComponent implements BlockableUI {
*/
@ContentChild('headericons') headericonsTemplate: TemplateRef<PanelHeaderIconsTemplateContext> | undefined;

@ViewChild('contentWrapper') contentWrapperViewChild: ElementRef;

readonly id = uuid('pn_id_');

get buttonAriaLabel() {
Expand Down Expand Up @@ -355,17 +357,32 @@ export class Panel extends BaseComponent implements BlockableUI {
expand() {
this.collapsed = false;
this.collapsedChange.emit(this.collapsed);
this.updateTabIndex();
}

collapse() {
this.collapsed = true;
this.collapsedChange.emit(this.collapsed);
this.updateTabIndex();
}

getBlockableElement(): HTMLElement {
return this.el.nativeElement.children[0];
}

updateTabIndex() {
if (this.contentWrapperViewChild) {
const focusableElements = this.contentWrapperViewChild.nativeElement.querySelectorAll('input, button, select, a, textarea, [tabindex]:not([tabindex="-1"])');
focusableElements.forEach((element: HTMLElement) => {
if (this.collapsed) {
element.setAttribute('tabindex', '-1');
} else {
element.removeAttribute('tabindex');
}
});
}
}

onKeyDown(event) {
if (event.code === 'Enter' || event.code === 'Space') {
this.toggle(event);
Expand Down

0 comments on commit 06a4c28

Please sign in to comment.