@@ -205,6 +205,7 @@ class Select {
205
205
SelectorEngine . findOne ( SELECTOR_INPUT , this . _clone ) . focus ( )
206
206
}
207
207
} )
208
+
208
209
}
209
210
210
211
_getConfig ( config , update ) {
@@ -333,6 +334,10 @@ class Select {
333
334
div . classList . add ( CLASS_NAME_SELECT_INLINE )
334
335
}
335
336
337
+ if ( this . _config . selectionType === 'tags' ) {
338
+ div . classList . add ( CLASS_NAME_SELECTION_TAGS )
339
+ }
340
+
336
341
this . _clone = div
337
342
this . _element . parentNode . insertBefore ( div , this . _element . nextSibling )
338
343
if ( ! this . _config . inline || ( this . _config . inline && this . _config . selection ) ) {
@@ -352,9 +357,6 @@ class Select {
352
357
_createSelection ( ) {
353
358
const span = document . createElement ( 'span' )
354
359
span . classList . add ( CLASS_NAME_SELECTION )
355
- if ( this . _config . selectionType === 'tags' ) {
356
- span . classList . add ( CLASS_NAME_SELECTION_TAGS )
357
- }
358
360
this . _clone . append ( span )
359
361
360
362
this . _updateSelection ( )
@@ -364,25 +366,14 @@ class Select {
364
366
_createSearchInput ( ) {
365
367
const input = document . createElement ( 'input' )
366
368
input . classList . add ( CLASS_NAME_SEARCH )
367
- // if (this._selection.length === 0) {
368
- // input.placeholder = this._config.searchPlaceholder
369
- // }
370
369
371
- // if (this._selection.length > 0 && !this._config.multiple) {
372
- // input.placeholder = this._selection[0].text
373
- // this._selectionElement.style.display = 'none'
370
+ // if (!this._config.inline && this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
371
+ // input.size = 2
374
372
// }
375
-
376
- // if (this._selection.length > 0 && this._config.multiple) {
377
- // input.placeholder = ''
378
- // }
379
-
380
- if ( this . _selection . length > 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
381
- input . size = 2
382
- }
373
+ this . _searchElement = input
374
+ this . _updateSearchSize ( )
383
375
384
376
this . _clone . append ( input )
385
- this . _searchElement = input
386
377
}
387
378
388
379
_createOptionsContainer ( ) {
@@ -402,11 +393,6 @@ class Select {
402
393
optionDiv . dataset . value = String ( option . value )
403
394
optionDiv . tabIndex = 0
404
395
optionDiv . innerHTML = option . text
405
- // if (option.selected) {
406
- // optionDiv.classList.add(CLASS_NAME_SELECTED)
407
- // // this._selectionAdd(String(option.value), option.text)
408
- // }
409
-
410
396
parentElement . append ( optionDiv )
411
397
}
412
398
@@ -431,7 +417,7 @@ class Select {
431
417
tag . dataset . value = value
432
418
tag . innerHTML = text
433
419
434
- const closeBtn = document . createElement ( 'button ' )
420
+ const closeBtn = document . createElement ( 'span ' )
435
421
closeBtn . classList . add ( CLASS_NAME_TAG_DELETE , 'close' )
436
422
closeBtn . setAttribute ( 'aria-label' , 'Close' )
437
423
closeBtn . innerHTML = '<span aria-hidden="true">×</span>'
@@ -490,6 +476,7 @@ class Select {
490
476
491
477
this . _updateSelection ( )
492
478
this . _updateSearch ( )
479
+ this . _updateSearchSize ( )
493
480
}
494
481
495
482
_selectionAdd ( value , text ) {
@@ -559,6 +546,10 @@ class Select {
559
546
}
560
547
561
548
_updateSearch ( ) {
549
+ if ( ! this . _config . search ) {
550
+ return
551
+ }
552
+
562
553
if ( this . _selection . length === 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
563
554
this . _searchElement . removeAttribute ( 'size' )
564
555
}
@@ -592,6 +583,17 @@ class Select {
592
583
}
593
584
}
594
585
586
+ _updateSearchSize ( size = 2 ) {
587
+ if ( ! this . _config . inline && this . _selection . length > 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
588
+ this . _searchElement . size = size
589
+ return
590
+ }
591
+
592
+ if ( this . _selection . length === 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
593
+ this . _searchElement . size . removeAttribute ( 'size' )
594
+ }
595
+ }
596
+
595
597
// .c-select-selections
596
598
597
599
_selectOption ( value ) {
@@ -635,14 +637,16 @@ class Select {
635
637
if ( element ) {
636
638
this . search ( element . value )
637
639
638
- if ( this . _selection . length > 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
639
- element . size = element . value . length + 1
640
- return
641
- }
640
+ this . _updateSearchSize ( element . value . length + 1 )
642
641
643
- if ( this . _selection . length === 0 && ( this . _config . selectionType === 'tags' || this . _config . selectionType === 'text' ) ) {
644
- element . removeAttribute ( 'size' )
645
- }
642
+ // if (!this._config.inline && this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
643
+ // element.size = element.value.length + 1
644
+ // return
645
+ // }
646
+
647
+ // if (this._selection.length === 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
648
+ // element.removeAttribute('size')
649
+ // }
646
650
}
647
651
}
648
652
0 commit comments