Skip to content

Commit d53f2af

Browse files
committed
rwk(*): put component css agnostic
1 parent 63d73bc commit d53f2af

File tree

5 files changed

+76
-105
lines changed

5 files changed

+76
-105
lines changed

src/auto-complete.component.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/auto-complete.template.html

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/input-tags.component.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {MAX_SAFE_INTEGER} from './input-tags.constants';
2-
import AutoCompleteComponent from './auto-complete.component';
32
import './input-tags.style.scss';
43

54
/**
@@ -11,8 +10,13 @@ import './input-tags.style.scss';
1110
* Renders an input box with tag editing support.
1211
*/
1312
class InputTags {
13+
constructor($element) {
14+
this.$element = $element;
15+
}
16+
1417
$onInit() {
1518
this.autocompleteVisible = false;
19+
this.element = this.$element[0];
1620

1721
this.tags = this.tags || [];
1822
this.suggestions = this.suggestions || {};
@@ -22,6 +26,8 @@ class InputTags {
2226
this.spellcheck = this.spellcheck || true;
2327
this.maxLength = this.maxLength || MAX_SAFE_INTEGER;
2428
this.inputDebounce = this.inputDebounce || 125;
29+
30+
this.reset();
2531
}
2632

2733
track(tag) {
@@ -85,8 +91,30 @@ class InputTags {
8591
this.autocompleteVisible = true;
8692
}
8793

88-
triggerBlur() {
89-
this.autocompleteVisible = false;
94+
triggerBlur(e) {
95+
if (e && this.element.contains(e.explicitOriginalTarget.parentNode)) {
96+
this.$element.find('input')[0].focus();
97+
} else {
98+
this.autocompleteVisible = false;
99+
this.reset();
100+
}
101+
}
102+
103+
reset() {
104+
this.currentItem = this.suggestions;
105+
this.path = [];
106+
}
107+
108+
next(item) {
109+
this.currentItem = item;
110+
this.path.push(item);
111+
}
112+
113+
previous() {
114+
this.path.pop();
115+
this.currentItem = this.path.length > 0 ?
116+
this.path[this.path.length - 1] :
117+
this.suggestions;
90118
}
91119
}
92120

@@ -114,6 +142,7 @@ const InputTagsComponent = {
114142
}
115143
};
116144

145+
InputTagsComponent.$inject = ['$element'];
146+
117147
angular.module('angularjs-input-tags', [])
118-
.component('inputTags', InputTagsComponent)
119-
.component('inputTagsAutoComplete', AutoCompleteComponent);
148+
.component('inputTags', InputTagsComponent);

src/input-tags.style.scss

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
input-tags {
2-
.host {
3-
width: 100%;
4-
outline: none;
5-
user-select:none;
2+
.ait-tag {
3+
display: inline-block;
64
}
75

8-
.input-group-addon {
9-
border-right: 0;
10-
}
11-
12-
.display {
13-
display: block;
6+
.ait-dropdown {
7+
position: absolute;
148
}
159
}

src/input-tags.template.html

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,46 @@
1-
<div class="host input-group"
2-
tabindex="-1"
3-
data-ng-blur="$ctrl.triggerBlur($event)"
4-
data-ng-focus="$ctrl.triggerFocus($event)">
5-
<div class="input-group-addon"
6-
data-ng-repeat="tag in $ctrl.tags track by $ctrl.track(tag)">
7-
<span class="tag-text" data-ng-bind="::$ctrl.getTagText(tag)"></span>
8-
<span style="cursor: pointer" ng-click="$ctrl.removeTag(tag)">
9-
&nbsp;&#x274c;
1+
<label class="ait-label">
2+
<ul class="ait-dropdown"
3+
ng-if="$ctrl.maxLength > $ctrl.tags.length"
4+
ng-show="$ctrl.autocompleteVisible">
5+
<li class="ait-dropdown--title"
6+
ng-if="$ctrl.path.length > 0"
7+
ng-click="$ctrl.previous()"
8+
ng-bind="$ctrl.currentItem[$ctrl.displayProperty] + '&lt;&nbsp;'">
9+
</li>
10+
<li class="ait-dropdown--title"
11+
ng-if="$ctrl.path.length === 0"
12+
ng-bind="$ctrl.currentItem[$ctrl.displayProperty]">
13+
</li>
14+
<li class="ait-dropdown--item"
15+
ng-repeat="item in $ctrl.currentItem.data track by item.code"
16+
ng-click="item.data && item.data.length > 0 ? $ctrl.next(item) : $ctrl.addTag(item)"
17+
ng-bind="item[$ctrl.displayProperty] + (item.data && item.data.length > 0 && '&nbsp;&gt;')">
18+
</li>
19+
</ul>
20+
21+
<div class="ait-tag"
22+
ng-repeat="tag in $ctrl.tags track by $ctrl.track(tag)">
23+
<span class="ait-tag--text"
24+
ng-bind="::$ctrl.getTagText(tag)"></span>
25+
<span class="ait-tag--close"
26+
style="cursor: pointer"
27+
ng-click="$ctrl.removeTag(tag)">
1028
</span>
1129
</div>
1230

13-
<input-tags-auto-complete source="$ctrl.suggestions"
14-
ng-if="$ctrl.maxLength > $ctrl.tags.length"
15-
display-property="$ctrl.displayProperty"
16-
on-tag-add="$ctrl.addTag(tag)"
17-
visible="$ctrl.autocompleteVisible"></input-tags-auto-complete>
18-
19-
<input class="form-control"
31+
<input class="ait-input"
32+
type="text"
2033
autocomplete="off"
21-
data-ng-trim="false"
34+
ng-trim="false"
2235
tabindex="{{$ctrl.tabindex}}"
2336
placeholder="{{$ctrl.placeholder}}"
2437
spellcheck="{{$ctrl.spellcheck}}"
25-
data-ng-if="$ctrl.maxLength > $ctrl.tags.length"
26-
data-ng-model="$ctrl.inputSearch"
38+
tabindex="-1"
39+
ng-focus="$ctrl.triggerFocus($event)"
40+
ng-blur="$ctrl.triggerBlur($event)"
41+
ng-if="$ctrl.maxLength > $ctrl.tags.length"
42+
ng-model="$ctrl.inputSearch"
2743
ng-model-options="{ debounce: $ctrl.inputDebounce }"
28-
data-ng-change="$ctrl.inputChange()"
29-
data-ng-disabled="$ctrl.disabled"
30-
data-ng-focus="$ctrl.triggerFocus($event)"
31-
data-ng-blur="$ctrl.triggerBlur($event)">
32-
</div>
44+
ng-change="$ctrl.inputChange()"
45+
ng-disabled="$ctrl.disabled" />
46+
</label>

0 commit comments

Comments
 (0)