@@ -2,14 +2,23 @@ import {computed} from '@angular/core';
2
2
import { ListboxInputs , ListboxPattern } from './listbox' ;
3
3
import { SignalLike } from '../behaviors/signal-like/signal-like' ;
4
4
import { OptionPattern } from './option' ;
5
- import { ComboboxPattern , ComboboxPopupControls } from '../combobox/combobox' ;
5
+ import { ComboboxPattern , ComboboxListboxControls } from '../combobox/combobox' ;
6
6
7
7
export type ComboboxListboxInputs < V > = ListboxInputs < V > & {
8
8
/** The combobox controlling the listbox. */
9
9
combobox : SignalLike < ComboboxPattern < OptionPattern < V > , V > | undefined > ;
10
10
} ;
11
11
12
- export class ComboboxListboxPattern < V > extends ListboxPattern < V > {
12
+ export class ComboboxListboxPattern < V >
13
+ extends ListboxPattern < V >
14
+ implements ComboboxListboxControls < OptionPattern < V > , V >
15
+ {
16
+ role = ( ) => 'listbox' as const ;
17
+
18
+ /** The id of the active (focused) item in the listbox. */
19
+ activeId = computed ( ( ) => this . listBehavior . activedescendant ( ) ) ;
20
+
21
+ /** The tabindex for the listbox. Always -1 because the combobox handles focus. */
13
22
override tabindex : SignalLike < - 1 | 0 > = ( ) => - 1 ;
14
23
15
24
constructor ( override readonly inputs : ComboboxListboxInputs < V > ) {
@@ -22,30 +31,52 @@ export class ComboboxListboxPattern<V> extends ListboxPattern<V> {
22
31
super ( inputs ) ;
23
32
}
24
33
34
+ /** Noop. The combobox handles keydown events. */
25
35
override onKeydown ( _ : KeyboardEvent ) : void { }
36
+
37
+ /** Noop. The combobox handles pointerdown events. */
26
38
override onPointerdown ( _ : PointerEvent ) : void { }
39
+
40
+ /** Noop. The combobox controls the open state. */
27
41
override setDefaultState ( ) : void { }
28
42
29
- /** The actions that can be performed on a combobox popup listbox. */
30
- comboboxActions : ComboboxPopupControls < OptionPattern < V > , V > = {
31
- activeId : computed ( ( ) => this . listBehavior . activedescendant ( ) ) ,
32
- next : ( ) => this . listBehavior . next ( ) ,
33
- prev : ( ) => this . listBehavior . prev ( ) ,
34
- last : ( ) => this . listBehavior . last ( ) ,
35
- first : ( ) => this . listBehavior . first ( ) ,
36
- unfocus : ( ) => this . listBehavior . unfocus ( ) ,
37
- select : item => this . listBehavior . select ( item ) ,
38
- clearSelection : ( ) => this . listBehavior . deselectAll ( ) ,
39
- getItem : e => this . _getItem ( e ) ,
40
- getSelectedItem : ( ) => this . inputs . items ( ) . find ( i => i . selected ( ) ) ,
41
- setValue : ( value : V | undefined ) => this . inputs . value . set ( value ? [ value ] : [ ] ) ,
42
- filter : ( text : string ) => {
43
- const filterFn = this . inputs . combobox ( ) ! . inputs . filter ( ) ;
44
-
45
- this . inputs . items ( ) . forEach ( i => {
46
- const isMatch = filterFn ( text , i . searchTerm ( ) ) ;
47
- i . inert . set ( isMatch ? null : true ) ;
48
- } ) ;
49
- } ,
43
+ /** Navigates to the next focusable item in the listbox. */
44
+ next = ( ) => this . listBehavior . next ( ) ;
45
+
46
+ /** Navigates to the previous focusable item in the listbox. */
47
+ prev = ( ) => this . listBehavior . prev ( ) ;
48
+
49
+ /** Navigates to the last focusable item in the listbox. */
50
+ last = ( ) => this . listBehavior . last ( ) ;
51
+
52
+ /** Navigates to the first focusable item in the listbox. */
53
+ first = ( ) => this . listBehavior . first ( ) ;
54
+
55
+ /** Unfocuses the currently focused item in the listbox. */
56
+ unfocus = ( ) => this . listBehavior . unfocus ( ) ;
57
+
58
+ /** Selects the specified item in the listbox. */
59
+ select = ( item ?: OptionPattern < V > ) => this . listBehavior . select ( item ) ;
60
+
61
+ /** Clears the selection in the listbox. */
62
+ clearSelection = ( ) => this . listBehavior . deselectAll ( ) ;
63
+
64
+ /** Retrieves the OptionPattern associated with a pointer event. */
65
+ getItem = ( e : PointerEvent ) => this . _getItem ( e ) ;
66
+
67
+ /** Retrieves the currently selected item in the listbox. */
68
+ getSelectedItem = ( ) => this . inputs . items ( ) . find ( i => i . selected ( ) ) ;
69
+
70
+ /** Sets the value of the combobox listbox. */
71
+ setValue = ( value : V | undefined ) => this . inputs . value . set ( value ? [ value ] : [ ] ) ;
72
+
73
+ /** Filters the items in the listbox based on the provided text. */
74
+ filter = ( text : string ) => {
75
+ const filterFn = this . inputs . combobox ( ) ! . inputs . filter ( ) ;
76
+
77
+ this . inputs . items ( ) . forEach ( i => {
78
+ const isMatch = filterFn ( text , i . searchTerm ( ) ) ;
79
+ i . inert . set ( isMatch ? null : true ) ;
80
+ } ) ;
50
81
} ;
51
82
}
0 commit comments