66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { computed , signal } from '@angular/core' ;
10+
911import { KeyboardEventManager } from '../behaviors/event-manager/keyboard-event-manager' ;
1012import { 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' ;
1624import { SignalLike } from '../behaviors/signal-like/signal-like' ;
1725
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+
1871/** The selection operations that the tablist can perform. */
1972interface SelectOptions {
2073 select ?: boolean ;
@@ -30,6 +83,34 @@ export type TabListInputs = ListNavigationInputs<TabPattern> &
3083 disabled : SignalLike < boolean > ;
3184 } ;
3285
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+ }
113+
33114/** Controls the state of a tablist. */
34115export class TabListPattern {
35116 /** Controls navigation for the tablist. */
0 commit comments