@@ -3,20 +3,16 @@ import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
3
3
import { Directionality } from '@angular/cdk/bidi' ;
4
4
import { NgTemplateOutlet } from '@angular/common' ;
5
5
import {
6
- afterNextRender ,
7
6
ChangeDetectionStrategy ,
8
7
Component ,
9
8
computed ,
10
9
contentChildren ,
11
- ElementRef ,
12
10
inject ,
13
11
Injector ,
14
12
input ,
15
13
model ,
16
- OnDestroy ,
17
14
output ,
18
15
signal ,
19
- viewChild ,
20
16
viewChildren ,
21
17
} from '@angular/core' ;
22
18
import { TabGroupHeaderComponent } from './tab-group-header.component' ;
@@ -37,20 +33,13 @@ import { TabComponent } from './tab.component';
37
33
] ) ,
38
34
] ,
39
35
} )
40
- export class TabGroupComponent implements OnDestroy {
36
+ export class TabGroupComponent {
41
37
tabs = contentChildren ( TabComponent ) ;
42
38
selectedIndex = model ( 0 ) ;
43
39
bodyGap = input ( true ) ;
44
40
45
41
tabHeaders = viewChildren ( TabGroupHeaderComponent ) ;
46
42
47
- tabHeadersEl = computed ( ( ) =>
48
- this . tabHeaders ( ) . map ( ( tabHeader ) => tabHeader . element )
49
- ) ;
50
-
51
- tabGroupHeader =
52
- viewChild . required < ElementRef < HTMLElement > > ( 'tabGroupHeader' ) ;
53
-
54
43
direction = inject ( Directionality ) ;
55
44
56
45
keyManager = new ActiveDescendantKeyManager (
@@ -74,42 +63,15 @@ export class TabGroupComponent implements OnDestroy {
74
63
tabInkWidth = signal ( 0 ) ;
75
64
tabInkLeft = signal ( 0 ) ;
76
65
77
- resizeObserver : ResizeObserver | undefined ;
78
-
79
- constructor ( ) {
80
- afterNextRender ( ( ) => {
81
- this . resizeObserver = new ResizeObserver ( ( ) => this . moveInk ( ) ) ;
82
- this . resizeObserver . observe ( this . tabGroupHeader ( ) . nativeElement ) ;
83
- } ) ;
84
- }
85
-
86
66
onTabGroupFocus ( ) {
87
67
if ( ! this . keyManager . activeItem ) {
88
68
this . keyManager . setFirstItemActive ( ) ;
89
69
}
90
70
}
91
71
92
- private moveInk ( ) {
93
- const index = this . selectedIndex ( ) ;
94
- const tabHeader = this . tabHeadersEl ( ) [ index ] ;
95
- const tabGroupHeader = this . tabGroupHeader ( ) ;
96
- if ( tabHeader ) {
97
- const rects = tabHeader . getBoundingClientRect ( ) ;
98
- const tabGroupRects =
99
- tabGroupHeader . nativeElement . getBoundingClientRect ( ) ;
100
- this . tabInkLeft . set ( rects . left - tabGroupRects . left ) ;
101
- this . tabInkWidth . set ( rects . width ) ;
102
- }
103
- }
104
-
105
72
selectTab ( $event : number ) {
106
73
this . keyManager . setActiveItem ( $event ) ;
107
74
this . selectedIndex . set ( $event ) ;
108
75
this . tabChanged . emit ( $event ) ;
109
- this . moveInk ( ) ;
110
- }
111
-
112
- ngOnDestroy ( ) : void {
113
- this . resizeObserver ?. disconnect ( ) ;
114
76
}
115
77
}
0 commit comments