6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { ModifierKey as Modifier } from '../behaviors/event-manager/event-manager' ;
10
9
import { KeyboardEventManager } from '../behaviors/event-manager/keyboard-event-manager' ;
11
10
import { PointerEventManager } from '../behaviors/event-manager/pointer-event-manager' ;
12
11
import { TabPattern } from './tab' ;
13
12
import { ListSelection , ListSelectionInputs } from '../behaviors/list-selection/list-selection' ;
14
13
import { ListNavigation , ListNavigationInputs } from '../behaviors/list-navigation/list-navigation' ;
15
14
import { ListFocus , ListFocusInputs } from '../behaviors/list-focus/list-focus' ;
16
- import { computed , Signal } from '@angular/core' ;
15
+ import { computed , signal , Signal } from '@angular/core' ;
17
16
18
17
/** The selection operations that the tablist can perform. */
19
18
interface SelectOptions {
@@ -28,7 +27,7 @@ interface SelectOptions {
28
27
29
28
/** The required inputs for the tablist. */
30
29
export type TablistInputs = ListNavigationInputs < TabPattern > &
31
- ListSelectionInputs < TabPattern > &
30
+ Omit < ListSelectionInputs < TabPattern > , 'multiselectable' > &
32
31
ListFocusInputs < TabPattern > & {
33
32
disabled : Signal < boolean > ;
34
33
} ;
@@ -56,12 +55,6 @@ export class TablistPattern {
56
55
/** The id of the current active tab. */
57
56
activedescendant = computed ( ( ) => this . focusManager . getActiveDescendant ( ) ) ;
58
57
59
- /** Whether multiple tabs in the tablist can be selected at once. */
60
- multiselectable : Signal < boolean > ;
61
-
62
- /** The number of tabs in the tablist. */
63
- setsize = computed ( ( ) => this . navigation . inputs . items ( ) . length ) ;
64
-
65
58
followFocus = computed ( ( ) => this . inputs . selectionMode ( ) === 'follow' ) ;
66
59
67
60
/** The key used to navigate to the previous tab in the tablist. */
@@ -84,50 +77,20 @@ export class TablistPattern {
84
77
keydown = computed ( ( ) => {
85
78
const manager = new KeyboardEventManager ( ) ;
86
79
87
- if ( ! this . followFocus ( ) ) {
88
- manager
89
- . on ( this . prevKey , ( ) => this . prev ( ) )
90
- . on ( this . nextKey , ( ) => this . next ( ) )
91
- . on ( 'Home' , ( ) => this . first ( ) )
92
- . on ( 'End' , ( ) => this . last ( ) ) ;
93
- }
94
-
95
80
if ( this . followFocus ( ) ) {
96
81
manager
97
82
. on ( this . prevKey , ( ) => this . prev ( { selectOne : true } ) )
98
83
. on ( this . nextKey , ( ) => this . next ( { selectOne : true } ) )
99
84
. on ( 'Home' , ( ) => this . first ( { selectOne : true } ) )
100
85
. on ( 'End' , ( ) => this . last ( { selectOne : true } ) ) ;
101
- }
102
-
103
- if ( this . inputs . multiselectable ( ) ) {
104
- manager
105
- . on ( Modifier . Shift , ' ' , ( ) => this . _updateSelection ( { selectFromAnchor : true } ) )
106
- . on ( Modifier . Shift , this . prevKey , ( ) => this . prev ( { toggle : true } ) )
107
- . on ( Modifier . Shift , this . nextKey , ( ) => this . next ( { toggle : true } ) )
108
- . on ( Modifier . Ctrl | Modifier . Shift , 'Home' , ( ) => this . first ( { selectFromActive : true } ) )
109
- . on ( Modifier . Ctrl | Modifier . Shift , 'End' , ( ) => this . last ( { selectFromActive : true } ) )
110
- . on ( Modifier . Ctrl , 'A' , ( ) => this . _updateSelection ( { selectAll : true } ) ) ;
111
- }
112
-
113
- if ( ! this . followFocus ( ) && this . inputs . multiselectable ( ) ) {
114
- manager
115
- . on ( ' ' , ( ) => this . _updateSelection ( { toggle : true } ) )
116
- . on ( 'Enter' , ( ) => this . _updateSelection ( { toggle : true } ) ) ;
117
- }
118
-
119
- if ( ! this . followFocus ( ) && ! this . inputs . multiselectable ( ) ) {
120
- manager
121
- . on ( ' ' , ( ) => this . _updateSelection ( { toggleOne : true } ) )
122
- . on ( 'Enter' , ( ) => this . _updateSelection ( { toggleOne : true } ) ) ;
123
- }
124
-
125
- if ( this . inputs . multiselectable ( ) && this . followFocus ( ) ) {
86
+ } else {
126
87
manager
127
- . on ( Modifier . Ctrl , this . prevKey , ( ) => this . prev ( ) )
128
- . on ( Modifier . Ctrl , this . nextKey , ( ) => this . next ( ) )
129
- . on ( Modifier . Ctrl , 'Home' , ( ) => this . first ( ) ) // TODO: Not in spec but prob should be.
130
- . on ( Modifier . Ctrl , 'End' , ( ) => this . last ( ) ) ; // TODO: Not in spec but prob should be.
88
+ . on ( this . prevKey , ( ) => this . prev ( ) )
89
+ . on ( this . nextKey , ( ) => this . next ( ) )
90
+ . on ( 'Home' , ( ) => this . first ( ) )
91
+ . on ( 'End' , ( ) => this . last ( ) )
92
+ . on ( ' ' , ( ) => this . _updateSelection ( { selectOne : true } ) )
93
+ . on ( 'Enter' , ( ) => this . _updateSelection ( { selectOne : true } ) ) ;
131
94
}
132
95
133
96
return manager ;
@@ -136,25 +99,21 @@ export class TablistPattern {
136
99
/** The pointerdown event manager for the tablist. */
137
100
pointerdown = computed ( ( ) => {
138
101
const manager = new PointerEventManager ( ) ;
139
-
140
- if ( this . inputs . multiselectable ( ) ) {
141
- manager
142
- . on ( e => this . goto ( e , { toggle : true } ) )
143
- . on ( Modifier . Shift , e => this . goto ( e , { selectFromActive : true } ) ) ;
144
- } else {
145
- manager . on ( e => this . goto ( e , { toggleOne : true } ) ) ;
146
- }
102
+ manager . on ( e => this . goto ( e , { selectOne : true } ) ) ;
147
103
148
104
return manager ;
149
105
} ) ;
150
106
151
107
constructor ( readonly inputs : TablistInputs ) {
152
108
this . disabled = inputs . disabled ;
153
109
this . orientation = inputs . orientation ;
154
- this . multiselectable = inputs . multiselectable ;
155
110
156
111
this . navigation = new ListNavigation ( inputs ) ;
157
- this . selection = new ListSelection ( { ...inputs , navigation : this . navigation } ) ;
112
+ this . selection = new ListSelection ( {
113
+ ...inputs ,
114
+ navigation : this . navigation ,
115
+ multiselectable : signal ( false ) ,
116
+ } ) ;
158
117
this . focusManager = new ListFocus ( { ...inputs , navigation : this . navigation } ) ;
159
118
}
160
119
0 commit comments