Skip to content

Commit bb320bd

Browse files
Refactor tab ids
1 parent ef084dc commit bb320bd

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/app/tab/tab-item/tab-item.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
role="tabpanel"
33
aria-live="off"
44
[hidden]="!active()"
5-
[id]="title().replaceAll(' ', '-') + '-tabpanel'"
6-
[attr.aria-labelledby]="title().replaceAll(' ', '-') + '-tab'">
5+
[id]="tabIdPrefix + 'Tabpanel'"
6+
[attr.aria-labelledby]="tabIdPrefix + 'Tab'">
77
<ng-content></ng-content>
88
</div>
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, effect, EventEmitter, input, model, Output } from '@angular/core';
2+
import { Component, effect, EventEmitter, input, model, OnInit, Output } from '@angular/core';
3+
import { camelCase } from 'lodash-es';
34

45
@Component({
56
selector: 'tab-item',
67
standalone: true,
78
imports: [CommonModule],
89
templateUrl: './tab-item.component.html',
910
})
10-
export class TabItemComponent {
11+
export class TabItemComponent implements OnInit {
1112
public active = model(false);
1213
public title = input.required<string>();
14+
public tabIdPrefix!: string;
1315
@Output() public tabSelected = new EventEmitter<void>();
1416

1517
constructor() {
@@ -19,4 +21,7 @@ export class TabItemComponent {
1921
}
2022
});
2123
}
24+
ngOnInit(): void {
25+
this.tabIdPrefix = camelCase(this.title());
26+
}
2227
}

src/app/tab/tabs/tabs.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<button
44
#tabButton
55
role="tab"
6-
[id]="tab.title().replaceAll(' ', '-') + '-tab'"
7-
[attr.aria-controls]="tab.title().replaceAll(' ', '-') + '-tabpanel'"
6+
[id]="tab.tabIdPrefix + 'Tab'"
7+
[attr.aria-controls]="tab.tabIdPrefix + 'Tabpanel'"
88
[class.tce-active-tab]="tab.active()"
99
[tabindex]="tab.active() ? 0 : -1"
1010
[attr.aria-selected]="tab.active() ? true : false"

0 commit comments

Comments
 (0)