66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { ModifierKey as Modifier } from '../behaviors/event-manager/event-manager' ;
109import { KeyboardEventManager } from '../behaviors/event-manager/keyboard-event-manager' ;
1110import { PointerEventManager } from '../behaviors/event-manager/pointer-event-manager' ;
1211import { TabPattern } from './tab' ;
1312import { ListSelection , ListSelectionInputs } from '../behaviors/list-selection/list-selection' ;
1413import { ListNavigation , ListNavigationInputs } from '../behaviors/list-navigation/list-navigation' ;
1514import { ListFocus , ListFocusInputs } from '../behaviors/list-focus/list-focus' ;
16- import { computed , Signal } from '@angular/core' ;
15+ import { computed , signal , Signal } from '@angular/core' ;
1716
1817/** The selection operations that the tablist can perform. */
1918interface SelectOptions {
@@ -28,7 +27,7 @@ interface SelectOptions {
2827
2928/** The required inputs for the tablist. */
3029export type TablistInputs = ListNavigationInputs < TabPattern > &
31- ListSelectionInputs < TabPattern > &
30+ Omit < ListSelectionInputs < TabPattern > , 'multiselectable' > &
3231 ListFocusInputs < TabPattern > & {
3332 disabled : Signal < boolean > ;
3433 } ;
@@ -56,12 +55,6 @@ export class TablistPattern {
5655 /** The id of the current active tab. */
5756 activedescendant = computed ( ( ) => this . focusManager . getActiveDescendant ( ) ) ;
5857
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-
6558 followFocus = computed ( ( ) => this . inputs . selectionMode ( ) === 'follow' ) ;
6659
6760 /** The key used to navigate to the previous tab in the tablist. */
@@ -84,50 +77,20 @@ export class TablistPattern {
8477 keydown = computed ( ( ) => {
8578 const manager = new KeyboardEventManager ( ) ;
8679
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-
9580 if ( this . followFocus ( ) ) {
9681 manager
9782 . on ( this . prevKey , ( ) => this . prev ( { selectOne : true } ) )
9883 . on ( this . nextKey , ( ) => this . next ( { selectOne : true } ) )
9984 . on ( 'Home' , ( ) => this . first ( { selectOne : true } ) )
10085 . 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 {
12687 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 } ) ) ;
13194 }
13295
13396 return manager ;
@@ -136,25 +99,21 @@ export class TablistPattern {
13699 /** The pointerdown event manager for the tablist. */
137100 pointerdown = computed ( ( ) => {
138101 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 } ) ) ;
147103
148104 return manager ;
149105 } ) ;
150106
151107 constructor ( readonly inputs : TablistInputs ) {
152108 this . disabled = inputs . disabled ;
153109 this . orientation = inputs . orientation ;
154- this . multiselectable = inputs . multiselectable ;
155110
156111 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+ } ) ;
158117 this . focusManager = new ListFocus ( { ...inputs , navigation : this . navigation } ) ;
159118 }
160119
0 commit comments