6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
+ import { computed , signal } from '@angular/core' ;
10
+
9
11
import { KeyboardEventManager } from '../behaviors/event-manager/keyboard-event-manager' ;
10
12
import { PointerEventManager } from '../behaviors/event-manager/pointer-event-manager' ;
11
- import { TabPattern } from './tab' ;
12
- import { ListSelection , ListSelectionInputs } from '../behaviors/list-selection/list-selection' ;
13
- import { ListNavigation , ListNavigationInputs } from '../behaviors/list-navigation/list-navigation' ;
14
- import { ListFocus , ListFocusInputs } from '../behaviors/list-focus/list-focus' ;
15
- import { computed , signal } from '@angular/core' ;
13
+ import { ListFocus , ListFocusInputs , ListFocusItem } from '../behaviors/list-focus/list-focus' ;
14
+ import {
15
+ ListNavigation ,
16
+ ListNavigationInputs ,
17
+ ListNavigationItem ,
18
+ } from '../behaviors/list-navigation/list-navigation' ;
19
+ import {
20
+ ListSelection ,
21
+ ListSelectionInputs ,
22
+ ListSelectionItem ,
23
+ } from '../behaviors/list-selection/list-selection' ;
16
24
import { SignalLike } from '../behaviors/signal-like/signal-like' ;
17
25
26
+ /** The required inputs to tabs. */
27
+ export interface TabInputs extends ListNavigationItem , ListSelectionItem < string > , ListFocusItem {
28
+ tablist : SignalLike < TabListPattern > ;
29
+ tabpanel : SignalLike < TabPanelPattern | undefined > ;
30
+ }
31
+
32
+ /** A tab in a tablist. */
33
+ export class TabPattern {
34
+ /** A global unique identifier for the tab. */
35
+ id : SignalLike < string > ;
36
+
37
+ /** A local unique identifier for the tab. */
38
+ value : SignalLike < string > ;
39
+
40
+ /** Whether the tab is selected. */
41
+ selected = computed ( ( ) => this . tablist ( ) . selection . inputs . value ( ) . includes ( this . value ( ) ) ) ;
42
+
43
+ /** A Tabpanel Id controlled by the tab. */
44
+ controls = computed ( ( ) => this . tabpanel ( ) ?. id ( ) ) ;
45
+
46
+ /** Whether the tab is disabled. */
47
+ disabled : SignalLike < boolean > ;
48
+
49
+ /** A reference to the parent tablist. */
50
+ tablist : SignalLike < TabListPattern > ;
51
+
52
+ /** A reference to the corresponding tabpanel. */
53
+ tabpanel : SignalLike < TabPanelPattern | undefined > ;
54
+
55
+ /** The tabindex of the tab. */
56
+ tabindex = computed ( ( ) => this . tablist ( ) . focusManager . getItemTabindex ( this ) ) ;
57
+
58
+ /** The html element that should receive focus. */
59
+ element : SignalLike < HTMLElement > ;
60
+
61
+ constructor ( inputs : TabInputs ) {
62
+ this . id = inputs . id ;
63
+ this . value = inputs . value ;
64
+ this . tablist = inputs . tablist ;
65
+ this . tabpanel = inputs . tabpanel ;
66
+ this . element = inputs . element ;
67
+ this . disabled = inputs . disabled ;
68
+ }
69
+ }
70
+
18
71
/** The selection operations that the tablist can perform. */
19
72
interface SelectOptions {
20
73
select ?: boolean ;
@@ -25,10 +78,38 @@ interface SelectOptions {
25
78
26
79
/** The required inputs for the tablist. */
27
80
export type TabListInputs = ListNavigationInputs < TabPattern > &
28
- Omit < ListSelectionInputs < TabPattern , string > , 'multi' > &
29
- ListFocusInputs < TabPattern > & {
30
- disabled : SignalLike < boolean > ;
31
- } ;
81
+ Omit < ListSelectionInputs < TabPattern , string > , 'multi' > &
82
+ ListFocusInputs < TabPattern > & {
83
+ disabled : SignalLike < boolean > ;
84
+ } ;
85
+
86
+ /** The required inputs for the tabpanel. */
87
+ export interface TabPanelInputs {
88
+ id : SignalLike < string > ;
89
+ tab : SignalLike < TabPattern | undefined > ;
90
+ value : SignalLike < string > ;
91
+ }
92
+
93
+ /** A tabpanel associated with a tab. */
94
+ export class TabPanelPattern {
95
+ /** A global unique identifier for the tabpanel. */
96
+ id : SignalLike < string > ;
97
+
98
+ /** A local unique identifier for the tabpanel. */
99
+ value : SignalLike < string > ;
100
+
101
+ /** A reference to the corresponding tab. */
102
+ tab : SignalLike < TabPattern | undefined > ;
103
+
104
+ /** Whether the tabpanel is hidden. */
105
+ hidden = computed ( ( ) => ! this . tab ( ) ?. selected ( ) ) ;
106
+
107
+ constructor ( inputs : TabPanelInputs ) {
108
+ this . id = inputs . id ;
109
+ this . value = inputs . value ;
110
+ this . tab = inputs . tab ;
111
+ }
112
+ }
32
113
33
114
/** Controls the state of a tablist. */
34
115
export class TabListPattern {
@@ -77,18 +158,18 @@ export class TabListPattern {
77
158
78
159
if ( this . followFocus ( ) ) {
79
160
manager
80
- . on ( this . prevKey , ( ) => this . prev ( { selectOne : true } ) )
81
- . on ( this . nextKey , ( ) => this . next ( { selectOne : true } ) )
82
- . on ( 'Home' , ( ) => this . first ( { selectOne : true } ) )
83
- . on ( 'End' , ( ) => this . last ( { selectOne : true } ) ) ;
161
+ . on ( this . prevKey , ( ) => this . prev ( { selectOne : true } ) )
162
+ . on ( this . nextKey , ( ) => this . next ( { selectOne : true } ) )
163
+ . on ( 'Home' , ( ) => this . first ( { selectOne : true } ) )
164
+ . on ( 'End' , ( ) => this . last ( { selectOne : true } ) ) ;
84
165
} else {
85
166
manager
86
- . on ( this . prevKey , ( ) => this . prev ( ) )
87
- . on ( this . nextKey , ( ) => this . next ( ) )
88
- . on ( 'Home' , ( ) => this . first ( ) )
89
- . on ( 'End' , ( ) => this . last ( ) )
90
- . on ( ' ' , ( ) => this . _updateSelection ( { selectOne : true } ) )
91
- . on ( 'Enter' , ( ) => this . _updateSelection ( { selectOne : true } ) ) ;
167
+ . on ( this . prevKey , ( ) => this . prev ( ) )
168
+ . on ( this . nextKey , ( ) => this . next ( ) )
169
+ . on ( 'Home' , ( ) => this . first ( ) )
170
+ . on ( 'End' , ( ) => this . last ( ) )
171
+ . on ( ' ' , ( ) => this . _updateSelection ( { selectOne : true } ) )
172
+ . on ( 'Enter' , ( ) => this . _updateSelection ( { selectOne : true } ) ) ;
92
173
}
93
174
94
175
return manager ;
0 commit comments