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

Fixed #16972 | Panel: Panel Content focusable and announced by assist… #17035

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
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
Loading