+
@@ -323,6 +323,8 @@ export class Panel extends BaseComponent implements AfterContentInit, BlockableU
_headerIconsTemplate: TemplateRef
| undefined;
+ @ViewChild('contentWrapper') contentWrapperViewChild: ElementRef;
+
readonly id = uuid('pn_id_');
get buttonAriaLabel() {
@@ -363,17 +365,32 @@ export class Panel extends BaseComponent implements AfterContentInit, BlockableU
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);
diff --git a/packages/primeng/src/tag/tag.ts b/packages/primeng/src/tag/tag.ts
index b63a0bf5c51..9f097a41e15 100755
--- a/packages/primeng/src/tag/tag.ts
+++ b/packages/primeng/src/tag/tag.ts
@@ -13,20 +13,22 @@ import { TagStyle } from './style/tagstyle';
standalone: true,
imports: [CommonModule, SharedModule],
template: `
-
-
-
-
-
-
-
-
- {{ value }}
+
+
+
+
+
+
+ {{ value }}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
- providers: [TagStyle]
+ providers: [TagStyle],
+ host: {
+ '[class]': 'containerClass()',
+ '[style]': 'style'
+ }
})
export class Tag extends BaseComponent implements AfterContentInit {
/**
@@ -88,11 +90,21 @@ export class Tag extends BaseComponent implements AfterContentInit {
}
containerClass() {
- return {
- 'p-tag p-component': true,
- [`p-tag-${this.severity}`]: this.severity,
- 'p-tag-rounded': this.rounded
- };
+ let classes = 'p-tag p-component';
+
+ if (this.severity) {
+ classes += ` p-tag-${this.severity}`;
+ }
+
+ if (this.rounded) {
+ classes += ' p-tag-rounded';
+ }
+
+ if (this.styleClass) {
+ classes += ` ${this.styleClass}`;
+ }
+
+ return classes;
}
}