Skip to content

Commit b477473

Browse files
authored
Fix style bootstrap 4/5 | Add property setting | Fix calcul dropdown height (#1892)
* fix: style dropdown bootstrap4/5 * fix: appareance with input-group class * feat: add ignoreOnDropdownHeight property * fix: calcul dropdownheight with optgroup * fix: style for input-group class * fix: add separator height to dropdown height calcul
1 parent e9ee9e6 commit b477473

File tree

4 files changed

+81
-16
lines changed

4 files changed

+81
-16
lines changed

src/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Selectize.defaults = {
5959
sizeValue: 'auto', // number of items or height value (px is default) or CSS height (px, rem, em, vh)
6060
},
6161
normalize: false,
62+
ignoreOnDropwdownHeight: 'img, i',
6263
/*
6364
load : null, // function(query, callback) { ... }
6465
score : null, // function(search) { ... }

src/scss/selectize.bootstrap4.scss

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,33 @@ $select-arrow-offset: calc(#{$select-padding-x} + 5px) !default;
167167
border-radius: 0;
168168
}
169169

170-
.input-group .#{$selectize}-input {
171-
overflow: unset;
172-
border-radius: 0 $select-border-radius $select-border-radius 0;
170+
.input-group .#{$selectize}-control:not(:last-child) {
171+
.#{$selectize}-input{
172+
overflow: unset;
173+
border-top-right-radius: 0;
174+
border-bottom-right-radius: 0;
175+
}
176+
}
177+
178+
.input-group .#{$selectize}-control:not(:first-child) {
179+
.#{$selectize}-input{
180+
overflow: unset;
181+
border-top-left-radius: 0;
182+
border-bottom-left-radius: 0;
183+
}
184+
}
185+
186+
// .input-group .#{$selectize}-input {
187+
// overflow: unset;
188+
// border-radius: 0 $select-border-radius $select-border-radius 0;
189+
// }
190+
191+
.#{selectize}-dropdown.plugin-auto_position.#{$selectize}-position-top {
192+
border-top: $select-border!important;
193+
border-bottom: $select-border!important;
194+
border-radius: $select-border-radius!important;
195+
}
196+
.#{selectize}-control.plugin-auto_position .#{selectize}-input.#{$selectize}-position-top.dropdown-active {
197+
border-radius: $select-border-radius!important;
198+
border-top: $select-border!important;
173199
}

src/scss/selectize.bootstrap5.scss

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,39 @@ $select-arrow-offset: calc(#{$select-padding-x} + 5px) !default;
167167
border-radius: 0;
168168
}
169169

170-
.input-group .#{$selectize}-input {
171-
overflow: unset;
172-
border-radius: 0 $select-border-radius $select-border-radius 0;
170+
.input-group>.input-group-append>.btn, .input-group>.form-control:not(:first-child) {
171+
border-top-left-radius: 0;
172+
border-bottom-left-radius: 0;
173+
}
174+
175+
.input-group>.input-group-prepend>.btn {
176+
border-top-right-radius: 0;
177+
border-bottom-right-radius: 0;
178+
}
179+
180+
181+
.input-group .#{$selectize}-control:not(:last-child) {
182+
.#{$selectize}-input{
183+
overflow: unset;
184+
border-top-right-radius: 0;
185+
border-bottom-right-radius: 0;
186+
}
187+
}
188+
189+
.input-group .#{$selectize}-control:not(:first-child) {
190+
.#{$selectize}-input{
191+
overflow: unset;
192+
border-top-left-radius: 0;
193+
border-bottom-left-radius: 0;
194+
}
173195
}
174196

175197
.#{selectize}-dropdown.plugin-auto_position.#{$selectize}-position-top {
176-
border-top: $select-border;
177-
border-bottom: $select-border;
178-
border-radius: $select-border-radius;
198+
border-top: $select-border!important;
199+
border-bottom: $select-border!important;
200+
border-radius: $select-border-radius!important;
179201
}
180202
.#{selectize}-control.plugin-auto_position .#{selectize}-input.#{$selectize}-position-top.dropdown-active {
181-
border-radius: $select-border-radius;
182-
border-top: $select-border;
203+
border-radius: $select-border-radius!important;
204+
border-top: $select-border!important;
183205
}

src/selectize.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,26 +1967,42 @@ $.extend(Selectize.prototype, {
19671967

19681968
if (this.settings.dropdownSize.sizeType === 'numberItems') {
19691969
// retrieve all items (included optgroup but exept the container .optgroup)
1970-
var $items = this.$dropdown_content.find('*').not('.optgroup, .highlight');
1970+
var $items = this.$dropdown_content.find('*').not('.optgroup, .highlight').not(this.settings.ignoreOnDropwdownHeight);
19711971
var totalHeight = 0;
1972+
var marginTop = 0;
1973+
var marginBottom = 0;
1974+
var separatorHeight = 0;
19721975

19731976

19741977
for (var i = 0; i < height; i++) {
19751978
var $item = $($items[i]);
19761979

1977-
if ($item.length === 0) break;
1980+
if ($item.length === 0) {
1981+
break;
1982+
}
19781983

1979-
totalHeight += $($items[i]).outerHeight(true);
1984+
totalHeight += $item.outerHeight(true);
19801985
// If not selectable, it's an optgroup so we "ignore" for count items
1981-
if (typeof $item.data('selectable') == 'undefined') height++;
1986+
if (typeof $item.data('selectable') == 'undefined') {
1987+
if ($item.hasClass('optgroup-header')) {
1988+
var styles = window.getComputedStyle($item.parent()[0], ':before');
1989+
1990+
if (styles) {
1991+
marginTop = styles.marginTop ? Number(styles.marginTop.replace(/\W*(\w)\w*/g, '$1')) : 0;
1992+
marginBottom = styles.marginBottom ? Number(styles.marginBottom.replace(/\W*(\w)\w*/g, '$1')) : 0;
1993+
separatorHeight = styles.borderTopWidth ? Number(styles.borderTopWidth.replace(/\W*(\w)\w*/g, '$1')) : 0;
1994+
}
1995+
}
1996+
height++;
1997+
}
19821998

19831999
}
19842000

19852001
// Get padding top for add to global height
19862002
var paddingTop = this.$dropdown_content.css('padding-top') ? Number(this.$dropdown_content.css('padding-top').replace(/\W*(\w)\w*/g, '$1')) : 0;
19872003
var paddingBottom = this.$dropdown_content.css('padding-bottom') ? Number(this.$dropdown_content.css('padding-bottom').replace(/\W*(\w)\w*/g, '$1')) : 0;
19882004

1989-
height = (totalHeight + paddingTop + paddingBottom) + 'px';
2005+
height = (totalHeight + paddingTop + paddingBottom + marginTop + marginBottom + separatorHeight) + 'px';
19902006
} else if (this.settings.dropdownSize.sizeType !== 'fixedHeight') {
19912007
console.warn('Selectize.js - Value of "sizeType" must be "fixedHeight" or "numberItems');
19922008
return;

0 commit comments

Comments
 (0)