@@ -2,14 +2,23 @@ import {computed} from '@angular/core';
22import { ListboxInputs , ListboxPattern } from './listbox' ;
33import { SignalLike } from '../behaviors/signal-like/signal-like' ;
44import { OptionPattern } from './option' ;
5- import { ComboboxPattern , ComboboxPopupControls } from '../combobox/combobox' ;
5+ import { ComboboxPattern , ComboboxListboxControls } from '../combobox/combobox' ;
66
77export type ComboboxListboxInputs < V > = ListboxInputs < V > & {
88 /** The combobox controlling the listbox. */
99 combobox : SignalLike < ComboboxPattern < OptionPattern < V > , V > | undefined > ;
1010} ;
1111
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. */
1322 override tabindex : SignalLike < - 1 | 0 > = ( ) => - 1 ;
1423
1524 constructor ( override readonly inputs : ComboboxListboxInputs < V > ) {
@@ -22,30 +31,52 @@ export class ComboboxListboxPattern<V> extends ListboxPattern<V> {
2231 super ( inputs ) ;
2332 }
2433
34+ /** Noop. The combobox handles keydown events. */
2535 override onKeydown ( _ : KeyboardEvent ) : void { }
36+
37+ /** Noop. The combobox handles pointerdown events. */
2638 override onPointerdown ( _ : PointerEvent ) : void { }
39+
40+ /** Noop. The combobox controls the open state. */
2741 override setDefaultState ( ) : void { }
2842
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+ } ) ;
5081 } ;
5182}
0 commit comments