Skip to content

Commit e416e47

Browse files
mentholkevin-brown
authored andcommitted
Added back dropdownAutoWidth option
This adds back the `dropdownAutoWidth` option, so the dropdown can have a width that is automatically determined by the browser. This works best for smaller dropdowns that contain options with large amounts of text. This closes select2#3103. This closes select2#3113. Signed-off-by: Kevin Brown <kevin@kevin-brown.com>
1 parent 86bf6dc commit e416e47

7 files changed

Lines changed: 34 additions & 10 deletions

File tree

dist/js/i18n/ru.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.full.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,9 +4098,16 @@ S2.define('select2/dropdown/attachBody',[
40984098
AttachBody.prototype._resizeDropdown = function () {
40994099
this.$dropdownContainer.width();
41004100

4101-
this.$dropdown.css({
4101+
var css = {
41024102
width: this.$container.outerWidth(false) + 'px'
4103-
});
4103+
};
4104+
4105+
if (this.options.get('dropdownAutoWidth')) {
4106+
css.minWidth = css.width;
4107+
css.width = 'auto';
4108+
}
4109+
4110+
this.$dropdown.css(css);
41044111
};
41054112

41064113
AttachBody.prototype._showDropdown = function (decorated) {
@@ -4619,6 +4626,7 @@ S2.define('select2/defaults',[
46194626
amdLanguageBase: './i18n/',
46204627
closeOnSelect: true,
46214628
debug: false,
4629+
dropdownAutoWidth: false,
46224630
escapeMarkup: Utils.escapeMarkup,
46234631
language: EnglishTranslation,
46244632
matcher: matcher,

dist/js/select2.full.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,9 +4098,16 @@ S2.define('select2/dropdown/attachBody',[
40984098
AttachBody.prototype._resizeDropdown = function () {
40994099
this.$dropdownContainer.width();
41004100

4101-
this.$dropdown.css({
4101+
var css = {
41024102
width: this.$container.outerWidth(false) + 'px'
4103-
});
4103+
};
4104+
4105+
if (this.options.get('dropdownAutoWidth')) {
4106+
css.minWidth = css.width;
4107+
css.width = 'auto';
4108+
}
4109+
4110+
this.$dropdown.css(css);
41044111
};
41054112

41064113
AttachBody.prototype._showDropdown = function (decorated) {
@@ -4619,6 +4626,7 @@ S2.define('select2/defaults',[
46194626
amdLanguageBase: './i18n/',
46204627
closeOnSelect: true,
46214628
debug: false,
4629+
dropdownAutoWidth: false,
46224630
escapeMarkup: Utils.escapeMarkup,
46234631
language: EnglishTranslation,
46244632
matcher: matcher,

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ define([
356356
amdLanguageBase: './i18n/',
357357
closeOnSelect: true,
358358
debug: false,
359+
dropdownAutoWidth: false,
359360
escapeMarkup: Utils.escapeMarkup,
360361
language: EnglishTranslation,
361362
matcher: matcher,

src/js/select2/dropdown/attachBody.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,16 @@ define([
179179
AttachBody.prototype._resizeDropdown = function () {
180180
this.$dropdownContainer.width();
181181

182-
this.$dropdown.css({
182+
var css = {
183183
width: this.$container.outerWidth(false) + 'px'
184-
});
184+
};
185+
186+
if (this.options.get('dropdownAutoWidth')) {
187+
css.minWidth = css.width;
188+
css.width = 'auto';
189+
}
190+
191+
this.$dropdown.css(css);
185192
};
186193

187194
AttachBody.prototype._showDropdown = function (decorated) {

0 commit comments

Comments
 (0)