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

Commit

Permalink
Merge 3a081d5 into bc0f0bd
Browse files Browse the repository at this point in the history
  • Loading branch information
fastf0rward committed Sep 15, 2014
2 parents bc0f0bd + 3a081d5 commit 35403f8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
scope.newTag.invalid = null;
})
.on('input-focus', function() {

// focus outer element
element.triggerHandler('focus');

ngModelCtrl.$setValidity('leftoverText', true);
})
.on('input-blur', function() {

// blur outer element
element.triggerHandler('blur');

if (!options.addFromAutocompleteOnly) {
if (options.addOnBlur) {
tagList.addText(scope.newTag.text);
Expand Down
28 changes: 28 additions & 0 deletions test/tags-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ describe('tags-input directive', function() {
// Assert
expect($scope.$digest).not.toHaveBeenCalled();
});

it('focuses the directive element when the input field receives focus', function() {
// Arrange
$scope.callback = jasmine.createSpy();
compile('ng-focus="callback()"');
var input = getInput()[0];

// Act
getInput().triggerHandler('focus');
$timeout.flush();

// Assert
expect($scope.callback).toHaveBeenCalled();
});

it('blurs the directive element when the input field loses focus', function() {
// Arrange
$scope.callback = jasmine.createSpy();
compile('ng-blur="callback()"');
var input = getInput()[0];

// Act
getInput().triggerHandler('blur');
$timeout.flush();

// Assert
expect($scope.callback).toHaveBeenCalled();
});
});

describe('tabindex option', function() {
Expand Down

0 comments on commit 35403f8

Please sign in to comment.