Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
fix(autosize): Re-size input when placeholder changes
Browse files Browse the repository at this point in the history
Fix the autosize directive so it correctly re-sizes the input element
when it's empty and its placeholder changes due to interpolation.

Closes #110
  • Loading branch information
mbenford committed Apr 12, 2014
1 parent f2dad2c commit 0eacc96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ tagsInput.directive('tiAutosize', function() {

ctrl.$parsers.unshift(resize);
ctrl.$formatters.unshift(resize);

attrs.$observe('placeholder', function(value) {
if (!ctrl.$modelValue) {
resize(value);
}
});
}
};
});
15 changes: 15 additions & 0 deletions test/autosize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ describe('autosize directive', function() {
expect(element.css('width')).toBe(getTextWidth('Some placeholder'));
});

it('sets the input width as the placeholder width when the input is empty and the placeholder changes', function() {
// Arrange
$scope.placeholder = 'Some placeholder';
compile('placeholder="{{placeholder}}"');
$scope.model = '';
$scope.$digest();

// Act
$scope.placeholder = 'Some very lengthy placeholder';
$scope.$digest();

// Assert
expect(element.css('width')).toBe(getTextWidth('Some very lengthy placeholder'));
});

it('clears the input width when it cannot be calculated', function() {
// Arrange
container.hide();
Expand Down

0 comments on commit 0eacc96

Please sign in to comment.