From 9de20af68f65934d5209cb9a8418b2f4a480275a Mon Sep 17 00:00:00 2001 From: Mator Date: Wed, 4 May 2016 21:40:36 -0700 Subject: [PATCH 1/2] added support for autosizing selects as well --- src/angular-elastic-input.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/angular-elastic-input.js b/src/angular-elastic-input.js index 27d427e..8ecf1b4 100644 --- a/src/angular-elastic-input.js +++ b/src/angular-elastic-input.js @@ -51,7 +51,12 @@ angular.module('puElasticInput', []).directive('puElasticInput', ['$document', ' wrapper.append(mirror); function update() { - mirror.text(element.val() || attrs.placeholder || ''); + if (element[0].tagName === "SELECT") { + var index = element[0].selectedIndex; + mirror.text((index > -1 && element[0].options[index].text) || attrs.placeholder || ''); + } else if (element[0].tagName === "INPUT") { + mirror.text(element.val() || attrs.placeholder || ''); + } var delta = parseInt(attrs.puElasticInputWidthDelta) || 1; element.css('width', mirror.prop('offsetWidth') + delta + 'px'); } From f4b63dc9a8bccfe601de79a5eee22c6419c8f0e7 Mon Sep 17 00:00:00 2001 From: Mator Date: Wed, 4 May 2016 22:01:20 -0700 Subject: [PATCH 2/2] may fix the issue with the size being a little two small. need to test more thoroughly. --- src/angular-elastic-input.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/angular-elastic-input.js b/src/angular-elastic-input.js index 8ecf1b4..b348b6e 100644 --- a/src/angular-elastic-input.js +++ b/src/angular-elastic-input.js @@ -51,13 +51,15 @@ angular.module('puElasticInput', []).directive('puElasticInput', ['$document', ' wrapper.append(mirror); function update() { + var defaultDelta = 1; if (element[0].tagName === "SELECT") { var index = element[0].selectedIndex; + defaultDelta = 8; mirror.text((index > -1 && element[0].options[index].text) || attrs.placeholder || ''); } else if (element[0].tagName === "INPUT") { mirror.text(element.val() || attrs.placeholder || ''); } - var delta = parseInt(attrs.puElasticInputWidthDelta) || 1; + var delta = parseInt(attrs.puElasticInputWidthDelta) || defaultDelta; element.css('width', mirror.prop('offsetWidth') + delta + 'px'); }