Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Added suport to insert chip on field blur #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dist/angular-chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@
return {
restrict: 'A',
require: '^chips',
scope: {
addOnBlur: '&?'
},
link: ChipControlLinkFun,
}
};
Expand All @@ -430,6 +433,10 @@
});
iElement.on('blur', function() {
chipsCtrl.setFocus(false);

if (scope.addOnBlur && event.target.value !== '' && chipsCtrl.addChip(event.target.value)) {
event.target.value = '';
}
});
};
})();
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-chips.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions dist/main.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
chip-tmpl {
display: inline-block;
margin: 0 5px 5px 0; }
margin: 0 5px 0 0; }

.default-chip {
border: 2px solid #e0e0e0;
border-radius: 5px;
background: #e0e0e0;
padding: 5px; }
padding: 0 5px; }

chip-tmpl:focus {
outline: none; }
chip-tmpl:focus .default-chip {
border: 2px solid #9e9e9e;
background: #9e9e9e;
color: white; }

Expand All @@ -29,9 +27,3 @@ chips {
font-size: 14px; }
chips > div > input:focus {
outline: none; }

.chip-out-focus {
border-bottom: 1px solid #e0e0e0; }

.chip-in-focus {
border-bottom: 1px solid #106cc8; }
12 changes: 6 additions & 6 deletions src/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ $chip-tmpl-focus-color: rgb(158, 158, 158);

chip-tmpl {
display: inline-block;
margin: 0 5px 5px 0;
margin: 0 5px 0 0;
}

.default-chip {
border: 2px solid $default-color;
// border: 2px solid $default-color;
border-radius: 5px;
background: $default-color;
padding: 5px;
padding: 0 5px;
}

chip-tmpl:focus {
outline: none;
.default-chip {
border: 2px solid $chip-tmpl-focus-color;
// border: 2px solid $chip-tmpl-focus-color;
background: $chip-tmpl-focus-color;
color: white;
}
Expand Down Expand Up @@ -46,9 +46,9 @@ chips {
}

.chip-out-focus {
border-bottom: 1px solid $default-color;
// border-bottom: 1px solid $default-color;
}

.chip-in-focus {
border-bottom: 1px solid $focus-color;
// border-bottom: 1px solid $focus-color;
}
7 changes: 7 additions & 0 deletions src/js/directives/controls/chip_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
return {
restrict: 'A',
require: '^chips',
scope: {
addOnBlur: '&?'
},
link: ChipControlLinkFun,
}
};
Expand All @@ -29,6 +32,10 @@
});
iElement.on('blur', function() {
chipsCtrl.setFocus(false);

if (scope.addOnBlur && event.target.value !== '' && chipsCtrl.addChip(event.target.value)) {
event.target.value = '';
}
});
};
})();