Skip to content

Commit

Permalink
fix: input and dropdown width
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienwnklr authored and risadams committed Dec 23, 2022
1 parent b7d625c commit 357678c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ $.extend(Selectize.prototype, {
// to have an identical rendering to a simple select (usefull for mobile device and do not open keyboard)
if (!self.settings.search) {
$control_input.attr('readonly', true);
$control_input.attr('inputmode', 'none');
$control_input.attr('inputmode', 'none');
$control.css('cursor', 'pointer');
}

Expand Down Expand Up @@ -2013,7 +2013,7 @@ $.extend(Selectize.prototype, {
var $control = this.$control;
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
offset.top += $control.outerHeight(true);
var w = $control[0].getBoundingClientRect().width;
var w = this.$wrapper[0].style.width !== 'fit-content' ? '100%' : 'max-content';
if (this.settings.minWidth && this.settings.minWidth > w)
{
w = this.settings.minWidth;
Expand All @@ -2023,6 +2023,12 @@ $.extend(Selectize.prototype, {
top : offset.top,
left : offset.left
});

if (w === 'max-content' && $control[0].getBoundingClientRect().width >= this.$dropdown[0].getBoundingClientRect().width) {
this.$dropdown.css({
width : '100%'
});
}
},

setupDropdownHeight: function () {
Expand Down
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,15 @@ var autoGrow = function ($input) {
}
}

var width = $input.attr('readonly') ? 0 : 4;
placeholder = $input.attr('placeholder');
if (placeholder) {
placeholderWidth = measureString(placeholder, $input) + 4;
placeholderWidth = measureString(placeholder, $input) + width;
} else {
placeholderWidth = 0;
}

width = Math.max(measureString(value, $input), placeholderWidth) + 4;
width = Math.max(measureString(value, $input), placeholderWidth) + width;
if (width !== currentWidth) {
currentWidth = width;
$input.width(width);
Expand Down

0 comments on commit 357678c

Please sign in to comment.