@@ -21,11 +21,15 @@ import {
21
21
ListSelectionInputs ,
22
22
ListSelectionItem ,
23
23
} from '../behaviors/list-selection/list-selection' ;
24
+ import { ShowHideControl , ShowHidePanel } from '../behaviors/show-hide/show-hide' ;
24
25
import { SignalLike } from '../behaviors/signal-like/signal-like' ;
25
26
26
27
/** The required inputs to tabs. */
27
28
export interface TabInputs extends ListNavigationItem , ListSelectionItem < string > , ListFocusItem {
29
+ /** The parent tablist that controls the tab. */
28
30
tablist : SignalLike < TabListPattern > ;
31
+
32
+ /** The remote tabpanel controlled by the tab. */
29
33
tabpanel : SignalLike < TabPanelPattern | undefined > ;
30
34
}
31
35
@@ -37,55 +41,41 @@ export class TabPattern {
37
41
/** A local unique identifier for the tab. */
38
42
value : SignalLike < string > ;
39
43
40
- /** Whether the tab is active . */
41
- active = computed ( ( ) => this . tablist ( ) ?. focusManager . activeItem ( ) === this ) ;
44
+ /** Whether the tab is disabled . */
45
+ disabled : SignalLike < boolean > ;
42
46
43
- /** Whether the tab is selected . */
44
- selected = computed ( ( ) => this . tablist ( ) . selection . inputs . value ( ) . includes ( this . value ( ) ) ) ;
47
+ /** The html element that should receive focus . */
48
+ element : SignalLike < HTMLElement > ;
45
49
46
- /** A Tabpanel Id controlled by the tab. */
47
- controls = computed ( ( ) => this . tabpanel ( ) ?. id ( ) ) ;
50
+ /** Controls the show-hide state for the tab. */
51
+ showHideControl : ShowHideControl ;
48
52
49
- /** Whether the tab is disabled . */
50
- disabled : SignalLike < boolean > ;
53
+ /** Whether the tab is active . */
54
+ active = computed ( ( ) => this . inputs . tablist ( ) . focusManager . activeItem ( ) === this ) ;
51
55
52
- /** A reference to the parent tablist. */
53
- tablist : SignalLike < TabListPattern > ;
56
+ /** Whether the tab is selected. */
57
+ selected = computed (
58
+ ( ) => ! ! this . inputs . tablist ( ) . selection . inputs . value ( ) . includes ( this . value ( ) ) ,
59
+ ) ;
54
60
55
- /** A reference to the corresponding tabpanel . */
56
- tabpanel : SignalLike < TabPanelPattern | undefined > ;
61
+ /** A tabpanel Id controlled by the tab . */
62
+ controls = computed ( ( ) => this . showHideControl . controls ( ) ) ;
57
63
58
64
/** The tabindex of the tab. */
59
- tabindex = computed ( ( ) => this . tablist ( ) . focusManager . getItemTabindex ( this ) ) ;
65
+ tabindex = computed ( ( ) => this . inputs . tablist ( ) . focusManager . getItemTabindex ( this ) ) ;
60
66
61
- /** The html element that should receive focus. */
62
- element : SignalLike < HTMLElement > ;
63
-
64
- constructor ( inputs : TabInputs ) {
67
+ constructor ( readonly inputs : TabInputs ) {
65
68
this . id = inputs . id ;
66
69
this . value = inputs . value ;
67
- this . tablist = inputs . tablist ;
68
- this . tabpanel = inputs . tabpanel ;
69
- this . element = inputs . element ;
70
70
this . disabled = inputs . disabled ;
71
+ this . element = inputs . element ;
72
+ this . showHideControl = new ShowHideControl ( {
73
+ visible : this . selected ,
74
+ showHidePanel : computed ( ( ) => inputs . tabpanel ( ) ?. showHidePanel ) ,
75
+ } ) ;
71
76
}
72
77
}
73
78
74
- /** The selection operations that the tablist can perform. */
75
- interface SelectOptions {
76
- select ?: boolean ;
77
- toggle ?: boolean ;
78
- toggleOne ?: boolean ;
79
- selectOne ?: boolean ;
80
- }
81
-
82
- /** The required inputs for the tablist. */
83
- export type TabListInputs = ListNavigationInputs < TabPattern > &
84
- Omit < ListSelectionInputs < TabPattern , string > , 'multi' > &
85
- ListFocusInputs < TabPattern > & {
86
- disabled : SignalLike < boolean > ;
87
- } ;
88
-
89
79
/** The required inputs for the tabpanel. */
90
80
export interface TabPanelInputs {
91
81
id : SignalLike < string > ;
@@ -101,19 +91,37 @@ export class TabPanelPattern {
101
91
/** A local unique identifier for the tabpanel. */
102
92
value : SignalLike < string > ;
103
93
104
- /** A reference to the corresponding tab. */
105
- tab : SignalLike < TabPattern | undefined > ;
94
+ /** Represents the show-hide state for the tabpanel. */
95
+ showHidePanel : ShowHidePanel ;
106
96
107
97
/** Whether the tabpanel is hidden. */
108
- hidden = computed ( ( ) => ! this . tab ( ) ?. selected ( ) ) ;
98
+ hidden = computed ( ( ) => this . showHidePanel . hidden ( ) ) ;
109
99
110
100
constructor ( inputs : TabPanelInputs ) {
111
101
this . id = inputs . id ;
112
102
this . value = inputs . value ;
113
- this . tab = inputs . tab ;
103
+ this . showHidePanel = new ShowHidePanel ( {
104
+ id : inputs . id ,
105
+ showHideControl : computed ( ( ) => inputs . tab ( ) ?. showHideControl ) ,
106
+ } ) ;
114
107
}
115
108
}
116
109
110
+ /** The selection operations that the tablist can perform. */
111
+ interface SelectOptions {
112
+ select ?: boolean ;
113
+ toggle ?: boolean ;
114
+ toggleOne ?: boolean ;
115
+ selectOne ?: boolean ;
116
+ }
117
+
118
+ /** The required inputs for the tablist. */
119
+ export type TabListInputs = ListNavigationInputs < TabPattern > &
120
+ Omit < ListSelectionInputs < TabPattern , string > , 'multi' > &
121
+ ListFocusInputs < TabPattern > & {
122
+ disabled : SignalLike < boolean > ;
123
+ } ;
124
+
117
125
/** Controls the state of a tablist. */
118
126
export class TabListPattern {
119
127
/** Controls navigation for the tablist. */
0 commit comments