Skip to content

Commit

Permalink
Fixed #16972 | Panel: Panel Content focusable and announced by assist…
Browse files Browse the repository at this point in the history
…ive technology even when collapsed
  • Loading branch information
mehmetcetin01140 committed Dec 12, 2024
1 parent 36ac7cd commit 349e49c
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 349e49c

Please sign in to comment.