@@ -209,7 +209,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
209
209
@Event ( ) ixBlur ! : EventEmitter < void > ;
210
210
211
211
@State ( ) dropdownShow = false ;
212
- @State ( ) selectedLabels : string [ ] = [ ] ;
212
+ @State ( ) selectedLabels : ( string | undefined ) [ ] = [ ] ;
213
213
@State ( ) isDropdownEmpty = false ;
214
214
@State ( ) navigationItem ?: DropdownItemWrapper ;
215
215
@State ( ) inputFilterText = '' ;
@@ -302,7 +302,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
302
302
303
303
@Watch ( 'dropdownShow' )
304
304
watchDropdownShow ( show : boolean ) {
305
- if ( show ) {
305
+ if ( show && this . dropdownRef ) {
306
306
this . arrowFocusController = new ArrowFocusController (
307
307
this . visibleNonShadowItems ,
308
308
this . dropdownRef ,
@@ -356,7 +356,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
356
356
}
357
357
358
358
private focusDropdownItem ( index : number ) {
359
- this . navigationItem = null ;
359
+ this . navigationItem = undefined ;
360
360
361
361
if ( index < this . visibleNonShadowItems . length ) {
362
362
const nestedDropdownItem =
@@ -402,7 +402,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
402
402
newItem . value = value ;
403
403
newItem . label = value ;
404
404
405
- this . customItemsContainerRef . appendChild ( newItem ) ;
405
+ this . customItemsContainerRef ? .appendChild ( newItem ) ;
406
406
407
407
this . clearInput ( ) ;
408
408
this . itemClick ( value ) ;
@@ -452,7 +452,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
452
452
this . selectedLabels = this . selectedItems . map ( ( item ) => item . label ) ;
453
453
454
454
if ( this . selectedLabels ?. length && this . isSingleMode ) {
455
- this . inputValue = this . selectedLabels [ 0 ] ;
455
+ this . inputValue = this . selectedLabels [ 0 ] ?? '' ;
456
456
} else {
457
457
this . inputValue = '' ;
458
458
}
@@ -468,7 +468,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
468
468
}
469
469
470
470
if ( ! value ) {
471
- this . itemSelectionChange . emit ( null ) ;
471
+ this . itemSelectionChange . emit ( [ ] ) ;
472
472
} else {
473
473
this . itemSelectionChange . emit ( Array . isArray ( value ) ? value : [ value ] ) ;
474
474
}
@@ -505,7 +505,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
505
505
this . cleanupResources ( ) ;
506
506
}
507
507
508
- private itemExists ( item : string ) {
508
+ private itemExists ( item : string | undefined ) {
509
509
return this . items . find ( ( i ) => i . label === item ) ;
510
510
}
511
511
@@ -519,7 +519,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
519
519
this . removeHiddenFromItems ( ) ;
520
520
this . isDropdownEmpty = this . isEveryDropdownItemHidden ;
521
521
} else {
522
- this . navigationItem = null ;
522
+ this . navigationItem = undefined ;
523
523
this . updateSelection ( ) ;
524
524
this . inputFilterText = '' ;
525
525
}
@@ -551,15 +551,17 @@ export class Select implements IxInputFieldComponent<string | string[]> {
551
551
return ;
552
552
}
553
553
554
+ const trimmedInput = this . inputFilterText . trim ( ) ;
555
+ const itemLabel = ( el as HTMLIxSelectItemElement ) ?. label ;
556
+
554
557
if (
555
- ! this . itemExists ( this . inputFilterText . trim ( ) ) &&
556
- ! this . itemExists ( ( el as HTMLIxSelectItemElement ) ?. label )
558
+ this . editable &&
559
+ ! this . itemExists ( trimmedInput ) &&
560
+ ! this . itemExists ( itemLabel )
557
561
) {
558
- if ( this . editable ) {
559
- const defaultPrevented = this . emitAddItem ( this . inputFilterText . trim ( ) ) ;
560
- if ( defaultPrevented ) {
561
- return ;
562
- }
562
+ const defaultPrevented = this . emitAddItem ( trimmedInput ) ;
563
+ if ( defaultPrevented ) {
564
+ return ;
563
565
}
564
566
}
565
567
@@ -622,16 +624,14 @@ export class Select implements IxInputFieldComponent<string | string[]> {
622
624
623
625
if (
624
626
this . isAddItemVisible ( ) &&
625
- this . addItemRef . contains (
627
+ this . addItemRef ? .contains (
626
628
await this . navigationItem . getDropdownItemElement ( )
627
629
)
628
630
) {
629
631
if ( moveUp ) {
630
632
this . applyFocusTo ( this . visibleItems . pop ( ) ) ;
631
- } else {
632
- if ( this . visibleItems . length ) {
633
- this . applyFocusTo ( this . visibleItems . shift ( ) ) ;
634
- }
633
+ } else if ( this . visibleItems . length ) {
634
+ this . applyFocusTo ( this . visibleItems . shift ( ) ) ;
635
635
}
636
636
return ;
637
637
}
@@ -687,7 +687,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
687
687
}
688
688
689
689
private filterItemsWithTypeahead ( ) {
690
- this . inputFilterText = this . inputRef ?. value || '' ;
690
+ this . inputFilterText = this . inputRef ?. value ?? '' ;
691
691
692
692
if ( this . isSingleMode && this . inputFilterText === this . selectedLabels [ 0 ] ) {
693
693
return ;
@@ -697,7 +697,9 @@ export class Select implements IxInputFieldComponent<string | string[]> {
697
697
this . items . forEach ( ( item ) => {
698
698
item . classList . remove ( 'd-none' ) ;
699
699
if (
700
- ! item . label . toLowerCase ( ) . includes ( this . inputFilterText . toLowerCase ( ) )
700
+ ! item . label
701
+ ?. toLowerCase ( )
702
+ . includes ( this . inputFilterText . toLowerCase ( ) )
701
703
) {
702
704
item . classList . add ( 'd-none' ) ;
703
705
}
@@ -801,15 +803,22 @@ export class Select implements IxInputFieldComponent<string | string[]> {
801
803
*/
802
804
@Method ( )
803
805
getNativeInputElement ( ) : Promise < HTMLInputElement > {
804
- return Promise . resolve ( this . inputRef ) ;
806
+ if ( this . inputRef ) {
807
+ return Promise . resolve ( this . inputRef ) ;
808
+ } else {
809
+ return Promise . reject ( new Error ( 'Input element not found' ) ) ;
810
+ }
805
811
}
806
812
807
813
/**
808
814
* Focuses the input field
809
815
*/
810
816
@Method ( )
811
817
async focusInput ( ) : Promise < void > {
812
- return ( await this . getNativeInputElement ( ) ) . focus ( ) ;
818
+ const inputElement = await this . getNativeInputElement ( ) ;
819
+ if ( inputElement ) {
820
+ inputElement . focus ( ) ;
821
+ }
813
822
}
814
823
815
824
render ( ) {
@@ -880,12 +889,14 @@ export class Select implements IxInputFieldComponent<string | string[]> {
880
889
ref = { ( ref ) => ( this . inputRef = ref ) }
881
890
onBlur = { ( e ) => this . onInputBlur ( e ) }
882
891
onFocus = { ( ) => {
883
- this . navigationItem = null ;
892
+ this . navigationItem = undefined ;
884
893
} }
885
894
onInput = { ( ) => this . filterItemsWithTypeahead ( ) }
886
895
onKeyDown = { ( e ) => this . onKeyDown ( e ) }
887
896
/>
888
897
{ this . allowClear &&
898
+ ! this . disabled &&
899
+ ! this . readonly &&
889
900
( this . selectedLabels ?. length || this . inputFilterText ) ? (
890
901
< ix-icon-button
891
902
class = "clear"
0 commit comments