Skip to content

Commit de07ba2

Browse files
committed
apply offscreen class after calculating width because offscreen class resets the width. also use css('width') when copying width if it returns a usable value. fixes select2#1140. fixes select2#1079
1 parent ec83e76 commit de07ba2

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

select2.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ the specific language governing permissions and limitations under the Apache Lic
119119
height: $template.height() - $template[0].clientHeight
120120
};
121121
$template.remove();
122-
122+
123123
return dim;
124124
}
125125

@@ -637,7 +637,6 @@ the specific language governing permissions and limitations under the Apache Lic
637637
// swap container for the element
638638
this.opts.element
639639
.data("select2", this)
640-
.addClass("select2-offscreen")
641640
.bind("focus.select2", function() { $(this).select2("focus"); })
642641
.attr("tabIndex", "-1")
643642
.before(this.container);
@@ -1574,12 +1573,12 @@ the specific language governing permissions and limitations under the Apache Lic
15741573
}
15751574
}
15761575

1577-
if (this.opts.width === "resolve") {
1578-
// next check if css('width') can resolve a width that is percent based, this is sometimes possible
1579-
// when attached to input type=hidden or elements hidden via css
1580-
style = this.opts.element.css('width');
1581-
if (style.indexOf("%") > 0) return style;
1576+
// next check if css('width') can resolve a width that is percent based, this is sometimes possible
1577+
// when attached to input type=hidden or elements hidden via css
1578+
style = this.opts.element.css('width');
1579+
if (style && style.length > 0) return style;
15821580

1581+
if (this.opts.width === "resolve") {
15831582
// finally, fallback on the calculated width of the element
15841583
return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
15851584
}
@@ -1593,6 +1592,7 @@ the specific language governing permissions and limitations under the Apache Lic
15931592
};
15941593

15951594
var width = resolveContainerWidth.call(this);
1595+
console.log("width: ",width);
15961596
if (width !== null) {
15971597
this.container.css("width", width);
15981598
}
@@ -1811,11 +1811,11 @@ the specific language governing permissions and limitations under the Apache Lic
18111811
}));
18121812
this.search.bind("focus", this.bind(function(){
18131813
this.container.addClass("select2-container-active");
1814-
}))
1814+
}));
18151815

18161816
this.initContainerWidth();
1817+
this.opts.element.addClass("select2-offscreen");
18171818
this.setPlaceholder();
1818-
18191819
},
18201820

18211821
// single
@@ -2251,6 +2251,7 @@ the specific language governing permissions and limitations under the Apache Lic
22512251
}));
22522252

22532253
this.initContainerWidth();
2254+
this.opts.element.addClass("select2-offscreen");
22542255

22552256
// set the placeholder if necessary
22562257
this.clearSearch();

0 commit comments

Comments
 (0)