Skip to content

Commit

Permalink
Merge pull request selectize#243 from enoshixi/master
Browse files Browse the repository at this point in the history
Updated measureString to return 0 for an empty string.
  • Loading branch information
brianreavis committed Feb 10, 2014
2 parents 2b5272b + 056edf9 commit 67ef826
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ var transferStyles = function($from, $to, properties) {
* @returns {int}
*/
var measureString = function(str, $parent) {
if (!str) {
return 0;
}

var $test = $('<test>').css({
position: 'absolute',
top: -99999,
Expand Down Expand Up @@ -283,6 +287,8 @@ var measureString = function(str, $parent) {
* @param {object} $input
*/
var autoGrow = function($input) {
var currentWidth = null;

var update = function(e) {
var value, keyCode, printable, placeholder, width;
var shift, character, selection;
Expand Down Expand Up @@ -325,7 +331,8 @@ var autoGrow = function($input) {
}

width = measureString(value, $input) + 4;
if (width !== $input.width()) {
if (width !== currentWidth) {
currentWidth = width;
$input.width(width);
$input.triggerHandler('resize');
}
Expand Down

0 comments on commit 67ef826

Please sign in to comment.