@@ -426,15 +426,17 @@ $.extend(Selectize.prototype, {
426
426
if ( ! self . isFocused ) {
427
427
// give control focus
428
428
if ( ! defaultPrevented ) {
429
- window . setTimeout ( function ( ) {
430
- self . focus ( ) ;
431
- } , 0 ) ;
429
+ window . setTimeout ( function ( ) {
430
+ if ( ! self . isOpen ) {
431
+ self . focus ( ) ;
432
+ }
433
+ } , 0 ) ;
432
434
}
433
435
}
434
436
// retain focus by preventing native handling. if the
435
437
// event target is the input it should not be modified.
436
438
// otherwise, text selection within the input won't work.
437
- if ( e . target !== self . $control_input [ 0 ] || self . $control_input . val ( ) === '' ) {
439
+ if ( $ target !== self . $control_input [ 0 ] || self . $control_input . val ( ) === '' ) {
438
440
if ( self . settings . mode === 'single' ) {
439
441
// toggle dropdown
440
442
self . isOpen ? self . close ( ) : self . open ( ) ;
@@ -443,15 +445,15 @@ $.extend(Selectize.prototype, {
443
445
self . setActiveItem ( null ) ;
444
446
}
445
447
if ( ! self . settings . openOnFocus ) {
446
- if ( self . isOpen && e . target === self . lastOpenTarget ) {
448
+ if ( self . isOpen && $ target === self . lastOpenTarget ) {
447
449
self . close ( ) ;
448
450
self . lastOpenTarget = false ;
449
451
} else if ( ! self . isOpen ) {
450
452
self . refreshOptions ( ) ;
451
453
self . open ( ) ;
452
- self . lastOpenTarget = e . target ;
454
+ self . lastOpenTarget = $ target;
453
455
} else {
454
- self . lastOpenTarget = e . target ;
456
+ self . lastOpenTarget = $ target;
455
457
}
456
458
}
457
459
}
@@ -1286,7 +1288,7 @@ $.extend(Selectize.prototype, {
1286
1288
$active = $create ;
1287
1289
}
1288
1290
self . setActiveOption ( $active ) ;
1289
- if ( triggerDropdown && ! self . isOpen ) { self . open ( ) ; }
1291
+ if ( triggerDropdown && ! self . isOpen && ! self . isFocused ) { self . open ( ) ; }
1290
1292
} else {
1291
1293
self . setActiveOption ( null ) ;
1292
1294
if ( triggerDropdown && self . isOpen ) { self . close ( ) ; }
@@ -2013,22 +2015,22 @@ $.extend(Selectize.prototype, {
2013
2015
var $control = this . $control ;
2014
2016
var offset = this . settings . dropdownParent === 'body' ? $control . offset ( ) : $control . position ( ) ;
2015
2017
offset . top += $control . outerHeight ( true ) ;
2016
- var w = this . $wrapper [ 0 ] . style . width !== 'fit-content' ? '100%' : 'max-content' ;
2018
+ var w = this . $wrapper [ 0 ] . style . width !== 'fit-content' ? this . settings . dropdownParent === 'body' ? 'max-content' : '100%' : 'max-content' ;
2017
2019
if ( this . settings . minWidth && this . settings . minWidth > w )
2018
2020
{
2019
2021
w = this . settings . minWidth ;
2020
2022
}
2021
- this . $dropdown . css ( {
2023
+
2024
+ if ( this . settings . dropdownParent !== 'body' && w === 'max-content' && $control . outerWidth ( true ) >= this . $dropdown . outerWidth ( true ) ) {
2025
+ w = '100%' ;
2026
+ }
2027
+
2028
+ this . $dropdown . css ( {
2022
2029
width : w ,
2030
+ minWidth : $control . outerWidth ( true ) ,
2023
2031
top : offset . top ,
2024
2032
left : offset . left
2025
2033
} ) ;
2026
-
2027
- if ( w === 'max-content' && $control [ 0 ] . getBoundingClientRect ( ) . width >= this . $dropdown [ 0 ] . getBoundingClientRect ( ) . width ) {
2028
- this . $dropdown . css ( {
2029
- width : '100%'
2030
- } ) ;
2031
- }
2032
2034
} ,
2033
2035
2034
2036
setupDropdownHeight : function ( ) {
0 commit comments