Skip to content

Commit 971c1f2

Browse files
committed
refactor(chip): code cleanup
1 parent 32c5792 commit 971c1f2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/chip-input/ux-chip-input.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
<require from="./ux-chip-input-theme"></require>
33

44
<ux-chip deletable
5+
ref="chiprepeat"
56
close.trigger="removeChip(chip)"
67
dblclick.trigger="editChip(chip)"
78
if.bind="type.toLowerCase() !== 'tag'"
89
repeat.for="chip of chipArray">
910
${chip}
1011
</ux-chip>
1112
<ux-tag deletable
13+
ref="tagrepeat"
1214
close.trigger="removeChip(chip)"
1315
dblclick.trigger="editChip(chip)"
1416
if.bind="type.toLowerCase() === 'tag'"

src/chip-input/ux-chip-input.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class UxChipInput implements Themable {
1515
@bindable public readonly: any = false;
1616
@bindable public theme = null;
1717
@bindable public type: any;
18-
@bindable public seperator: string;
18+
@bindable public separator: string;
1919

2020
@bindable({ defaultBindingMode: bindingMode.twoWay })
2121
public value: any = undefined;
@@ -25,6 +25,8 @@ export class UxChipInput implements Themable {
2525

2626
public view: View;
2727
private textbox: HTMLInputElement;
28+
private chiprepeat: Element;
29+
private tagrepeat: Element;
2830

2931
constructor(private element: HTMLInputElement, public resources: ViewResources, private styleEngine: StyleEngine) { }
3032

@@ -48,10 +50,14 @@ export class UxChipInput implements Themable {
4850

4951
if (this.disabled || this.disabled === '') {
5052
this.textbox.setAttribute('disabled', '');
53+
this.chiprepeat.removeAttribute('deletable');
54+
this.tagrepeat.removeAttribute('deletable');
5155
}
5256

5357
if (this.readonly || this.readonly === '') {
5458
this.textbox.setAttribute('readonly', '');
59+
this.chiprepeat.removeAttribute('deletable');
60+
this.tagrepeat.removeAttribute('deletable');
5561
}
5662
}
5763

@@ -125,19 +131,18 @@ export class UxChipInput implements Themable {
125131
public chipsChanged() {
126132
let seperator = ', ';
127133

128-
if (this.seperator) {
129-
seperator = this.seperator;
134+
if (this.separator) {
135+
seperator = this.separator;
130136
}
131137

132138
this.value = this.chipArray.join(seperator);
133-
134139
}
135140

136141
public valueChanged() {
137142
let seperator = ', ';
138143

139-
if (this.seperator) {
140-
seperator = this.seperator;
144+
if (this.separator) {
145+
seperator = this.separator;
141146
}
142147

143148
this.chipArray = this.value.split(seperator);
@@ -146,16 +151,24 @@ export class UxChipInput implements Themable {
146151
public disabledChanged(newValue: any) {
147152
if (newValue === true || newValue === '') {
148153
this.textbox.setAttribute('disabled', 'true');
154+
this.chiprepeat.removeAttribute('deletable');
155+
this.tagrepeat.removeAttribute('deletable');
149156
} else {
150157
this.textbox.removeAttribute('disabled');
158+
this.chiprepeat.setAttribute('deletable', '');
159+
this.tagrepeat.setAttribute('deletable', '');
151160
}
152161
}
153162

154163
public readonlyChanged(newValue: any) {
155164
if (newValue === true || newValue === '') {
156165
this.textbox.setAttribute('readonly', 'true');
166+
this.chiprepeat.removeAttribute('deletable');
167+
this.tagrepeat.removeAttribute('deletable');
157168
} else {
158169
this.textbox.removeAttribute('readonly');
170+
this.chiprepeat.setAttribute('deletable', '');
171+
this.tagrepeat.setAttribute('deletable', '');
159172
}
160173
}
161174

0 commit comments

Comments
 (0)