File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -499,6 +499,31 @@ describe('Combobox', () => {
499499 input ( '' ) ;
500500 expect ( getOptions ( ) . length ) . toBe ( 50 ) ;
501501 } ) ;
502+
503+ it ( 'should determine the highlighted state on open' , ( ) => {
504+ setupCombobox ( { filterMode : 'highlight' } ) ;
505+ focus ( ) ;
506+ input ( 'N' ) ;
507+ expect ( inputElement . value ) . toBe ( 'Nebraska' ) ;
508+ expect ( inputElement . selectionEnd ) . toBe ( 8 ) ;
509+ expect ( inputElement . selectionStart ) . toBe ( 1 ) ;
510+ expect ( getOptions ( ) . length ) . toBe ( 8 ) ;
511+
512+ escape ( ) ; // close
513+ inputElement . selectionStart = 2 ; // Change highlighting
514+ down ( ) ; // open
515+
516+ expect ( inputElement . value ) . toBe ( 'Nebraska' ) ;
517+ expect ( inputElement . selectionEnd ) . toBe ( 8 ) ;
518+ expect ( inputElement . selectionStart ) . toBe ( 2 ) ;
519+ expect ( getOptions ( ) . length ) . toBe ( 6 ) ;
520+
521+ escape ( ) ; // close
522+ inputElement . selectionStart = 3 ; // Change highlighting
523+ down ( ) ; // open
524+
525+ expect ( getOptions ( ) . length ) . toBe ( 1 ) ;
526+ } ) ;
502527 } ) ;
503528
504529 // describe('with programmatic value changes', () => {
Original file line number Diff line number Diff line change @@ -391,6 +391,17 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
391391 open ( nav ?: { first ?: boolean ; last ?: boolean } ) {
392392 this . expanded . set ( true ) ;
393393
394+ const inputEl = this . inputs . inputEl ( ) ;
395+
396+ if ( inputEl ) {
397+ const isHighlighting = inputEl . selectionStart !== inputEl . value . length ;
398+ this . inputs . inputValue ?. set ( inputEl . value . slice ( 0 , inputEl . selectionStart || 0 ) ) ;
399+
400+ if ( ! isHighlighting ) {
401+ this . highlightedItem . set ( undefined ) ;
402+ }
403+ }
404+
394405 if ( nav ?. first ) {
395406 this . first ( ) ;
396407 }
You can’t perform that action at this time.
0 commit comments