11import type { ReactiveController } from 'lit' ;
22import type { Ref } from 'lit/directives/ref.js' ;
3-
43import {
5- type KeyBindingOptions ,
64 addKeybindings ,
75 altKey ,
86 arrowDown ,
@@ -11,6 +9,7 @@ import {
119 enterKey ,
1210 escapeKey ,
1311 homeKey ,
12+ type KeyBindingOptions ,
1413 shiftKey ,
1514 spaceBar ,
1615 tabKey ,
@@ -54,20 +53,20 @@ export class ComboNavigationController<T extends object> {
5453 return this . _config . list . value ! ;
5554 }
5655
57- protected get firstItem ( ) : number {
56+ protected get _firstItem ( ) : number {
5857 return this . state . dataState . findIndex ( ( rec ) => ! rec . header ) ;
5958 }
6059
61- protected get lastItem ( ) : number {
60+ protected get _lastItem ( ) : number {
6261 return this . state . dataState . length - 1 ;
6362 }
6463
65- protected async hide ( ) : Promise < boolean > {
64+ protected async _hide ( ) : Promise < boolean > {
6665 // @ts -expect-error: protected access
6766 return await this . combo . _hide ( true ) ;
6867 }
6968
70- protected async show ( ) : Promise < boolean > {
69+ protected async _show ( ) : Promise < boolean > {
7170 // @ts -expect-error: protected access
7271 return await this . combo . _show ( true ) ;
7372 }
@@ -77,12 +76,12 @@ export class ComboNavigationController<T extends object> {
7776 this . combo . toggleSelect ( index ) ;
7877 }
7978
80- protected select ( index : number ) : void {
79+ protected _select ( index : number ) : void {
8180 // @ts -expect-error: protected access
8281 this . combo . selectByIndex ( index ) ;
8382 }
8483
85- private onSpace = ( ) : void => {
84+ private _onSpace = ( ) : void => {
8685 if ( this . _active === - 1 ) {
8786 return ;
8887 }
@@ -93,71 +92,71 @@ export class ComboNavigationController<T extends object> {
9392 }
9493 } ;
9594
96- private onEnter = async ( ) : Promise < void > => {
95+ private _onEnter = async ( ) : Promise < void > => {
9796 if ( this . _active === - 1 ) {
9897 return ;
9998 }
10099
101100 const item = this . state . dataState [ this . _active ] ;
102101
103102 if ( ! item . header && this . combo . singleSelect ) {
104- this . select ( this . active ) ;
103+ this . _select ( this . active ) ;
105104 }
106105
107- if ( await this . hide ( ) ) {
106+ if ( await this . _hide ( ) ) {
108107 this . input . select ( ) ;
109108 this . combo . focus ( ) ;
110109 }
111110 } ;
112111
113- private onTab = async ( ) : Promise < void > => {
112+ private _onTab = async ( ) : Promise < void > => {
114113 if ( this . combo . open ) {
115- await this . hide ( ) ;
114+ await this . _hide ( ) ;
116115 }
117116 } ;
118117
119- private onEscape = async ( ) : Promise < void > => {
120- if ( await this . hide ( ) ) {
118+ private _onEscape = async ( ) : Promise < void > => {
119+ if ( await this . _hide ( ) ) {
121120 this . input . focus ( ) ;
122121 }
123122 } ;
124123
125- private onMainInputArrowDown = async ( ) : Promise < void > => {
126- if ( ! this . combo . open && ! ( await this . show ( ) ) ) {
124+ private _onMainInputArrowDown = async ( ) : Promise < void > => {
125+ if ( ! this . combo . open && ! ( await this . _show ( ) ) ) {
127126 return ;
128127 }
129128
130129 if ( this . combo . singleSelect ) {
131- this . onSearchArrowDown ( ) ;
130+ this . _onSearchArrowDown ( ) ;
132131 }
133132 } ;
134133
135- private onSearchArrowDown = ( ) : void => {
134+ private _onSearchArrowDown = ( ) : void => {
136135 this . list . focus ( ) ;
137- this . onArrowDown ( ) ;
136+ this . _onArrowDown ( ) ;
138137 } ;
139138
140- private onHome = ( ) : void => {
141- this . active = this . firstItem ;
142- this . scrollToActive ( ) ;
139+ private _onHome = ( ) : void => {
140+ this . active = this . _firstItem ;
141+ this . _scrollToActive ( ) ;
143142 } ;
144143
145- private onEnd = ( ) : void => {
146- this . active = this . lastItem ;
147- this . scrollToActive ( ) ;
144+ private _onEnd = ( ) : void => {
145+ this . active = this . _lastItem ;
146+ this . _scrollToActive ( ) ;
148147 } ;
149148
150- private onArrowUp = ( ) : void => {
151- this . getNextItem ( - 1 ) ;
152- this . scrollToActive ( ) ;
149+ private _onArrowUp = ( ) : void => {
150+ this . _getNextItem ( - 1 ) ;
151+ this . _scrollToActive ( ) ;
153152 } ;
154153
155- private onArrowDown = ( ) : void => {
156- this . getNextItem ( 1 ) ;
157- this . scrollToActive ( ) ;
154+ private _onArrowDown = ( ) : void => {
155+ this . _getNextItem ( 1 ) ;
156+ this . _scrollToActive ( ) ;
158157 } ;
159158
160- private scrollToActive ( behavior ?: ScrollBehavior ) : void {
159+ private _scrollToActive ( behavior ?: ScrollBehavior ) : void {
161160 this . list . element ( this . active ) ?. scrollIntoView ( {
162161 block : 'center' ,
163162 behavior : behavior ?? 'auto' ,
@@ -166,7 +165,7 @@ export class ComboNavigationController<T extends object> {
166165 this . list . requestUpdate ( ) ;
167166 }
168167
169- private getNearestItem ( start : number , delta : - 1 | 1 ) : number {
168+ private _getNearestItem ( start : number , delta : - 1 | 1 ) : number {
170169 let index = start ;
171170 const items = this . state . dataState ;
172171
@@ -179,10 +178,10 @@ export class ComboNavigationController<T extends object> {
179178 return index >= 0 && index < items . length ? index : - 1 ;
180179 }
181180
182- private getNextItem ( delta : - 1 | 1 ) : void {
183- const next = this . getNearestItem ( this . _active , delta ) ;
181+ private _getNextItem ( delta : - 1 | 1 ) : void {
182+ const next = this . _getNearestItem ( this . _active , delta ) ;
184183 if ( next === - 1 ) {
185- if ( this . active === this . firstItem ) {
184+ if ( this . active === this . _firstItem ) {
186185 ( this . combo . singleSelect ? this . input : this . searchInput ) . focus ( ) ;
187186 this . active = - 1 ;
188187 }
@@ -201,50 +200,49 @@ export class ComboNavigationController<T extends object> {
201200 this . _config = config ;
202201
203202 const bindingDefaults = {
204- preventDefault : true ,
205203 triggers : [ 'keydownRepeat' ] ,
206204 } as KeyBindingOptions ;
207205
208206 const skip = ( ) : boolean => this . combo . disabled ;
209207
210208 // Combo
211209 addKeybindings ( this . combo , { skip, bindingDefaults } )
212- . set ( tabKey , this . onTab , { preventDefault : false } )
213- . set ( [ shiftKey , tabKey ] , this . onTab , { preventDefault : false } )
214- . set ( escapeKey , this . onEscape ) ;
210+ . set ( tabKey , this . _onTab , { preventDefault : false } )
211+ . set ( [ shiftKey , tabKey ] , this . _onTab , { preventDefault : false } )
212+ . set ( escapeKey , this . _onEscape ) ;
215213
216214 // Main input
217215 addKeybindings ( this . combo , {
218216 skip,
219217 ref : this . _config . input ,
220218 bindingDefaults,
221219 } )
222- . set ( arrowUp , async ( ) => await this . hide ( ) )
223- . set ( [ altKey , arrowDown ] , this . onMainInputArrowDown )
224- . set ( arrowDown , this . onMainInputArrowDown )
225- . set ( enterKey , this . onEnter ) ;
220+ . set ( arrowUp , async ( ) => await this . _hide ( ) )
221+ . set ( [ altKey , arrowDown ] , this . _onMainInputArrowDown )
222+ . set ( arrowDown , this . _onMainInputArrowDown )
223+ . set ( enterKey , this . _onEnter ) ;
226224
227225 // Search input
228226 addKeybindings ( this . combo , {
229227 skip,
230228 ref : this . _config . search ,
231229 bindingDefaults,
232230 } )
233- . set ( arrowUp , this . onEscape )
234- . set ( arrowDown , this . onSearchArrowDown ) ;
231+ . set ( arrowUp , this . _onEscape )
232+ . set ( arrowDown , this . _onSearchArrowDown ) ;
235233
236234 // List
237235 addKeybindings ( this . combo , {
238236 skip,
239237 ref : this . _config . list ,
240238 bindingDefaults,
241239 } )
242- . set ( arrowUp , this . onArrowUp )
243- . set ( arrowDown , this . onArrowDown )
244- . set ( homeKey , this . onHome )
245- . set ( endKey , this . onEnd )
246- . set ( spaceBar , this . onSpace )
247- . set ( enterKey , this . onEnter ) ;
240+ . set ( arrowUp , this . _onArrowUp )
241+ . set ( arrowDown , this . _onArrowDown )
242+ . set ( homeKey , this . _onHome )
243+ . set ( endKey , this . _onEnd )
244+ . set ( spaceBar , this . _onSpace )
245+ . set ( enterKey , this . _onEnter ) ;
248246 }
249247
250248 public hostDisconnected ( ) : void {
0 commit comments