Skip to content

Commit 39265c6

Browse files
committed
Merge branch 'main' into v14/chore/implicit-overwrite
2 parents d2b8e3d + d590af3 commit 39265c6

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

src/packages/tags/components/tags-input/tags-input.element.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ export class UmbTagsInputElement extends UUIFormControlMixin(UmbLitElement, '')
3434
return this._items;
3535
}
3636

37+
/**
38+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
39+
* @type {boolean}
40+
* @attr
41+
* @default false
42+
*/
43+
@property({ type: Boolean, reflect: true })
44+
readonly = false;
45+
3746
@state()
3847
private _matches: Array<TagResponseModel> = [];
3948

@@ -188,18 +197,7 @@ export class UmbTagsInputElement extends UUIFormControlMixin(UmbLitElement, '')
188197
<uui-tag id="input-width-tracker" aria-hidden="true" style="visibility:hidden;opacity:0;position:absolute;">
189198
${this._currentInput}
190199
</uui-tag>
191-
<uui-tag look="outline" id="main-tag" @click="${this.focus}" slot="trigger">
192-
<input
193-
id="tag-input"
194-
aria-label="tag input"
195-
placeholder="Enter tag"
196-
.value="${this._currentInput ?? undefined}"
197-
@keydown="${this.#onKeydown}"
198-
@input="${this.#onInput}"
199-
@blur="${this.#onBlur}" />
200-
<uui-icon id="icon-add" name="icon-add"></uui-icon>
201-
${this.#renderTagOptions()}
202-
</uui-tag>
200+
${this.#renderAddButton()}
203201
</span>
204202
</div>
205203
`;
@@ -210,7 +208,7 @@ export class UmbTagsInputElement extends UUIFormControlMixin(UmbLitElement, '')
210208
return html`
211209
<uui-tag class="tag">
212210
<span>${tag}</span>
213-
<uui-icon name="icon-wrong" @click="${() => this.#delete(tag)}"></uui-icon>
211+
${this.#renderRemoveButton(tag)}
214212
</uui-tag>
215213
`;
216214
})}`;
@@ -233,14 +231,39 @@ export class UmbTagsInputElement extends UUIFormControlMixin(UmbLitElement, '')
233231
name="${tag.group ?? ''}"
234232
@click="${() => this.#optionClick(index)}"
235233
@keydown="${(e: KeyboardEvent) => this.#optionKeydown(e, index)}"
236-
value="${tag.text ?? ''}" />
234+
value="${tag.text ?? ''}"
235+
?readonly=${this.readonly} />
237236
<label for="tag-${tag.id}"> ${tag.text} </label>`;
238237
},
239238
)}
240239
</div>
241240
`;
242241
}
243242

243+
#renderAddButton() {
244+
if (this.readonly) return nothing;
245+
246+
return html`
247+
<uui-tag look="outline" id="main-tag" @click="${this.focus}" slot="trigger">
248+
<input
249+
id="tag-input"
250+
aria-label="tag input"
251+
placeholder="Enter tag"
252+
.value="${this._currentInput ?? undefined}"
253+
@keydown="${this.#onKeydown}"
254+
@input="${this.#onInput}"
255+
@blur="${this.#onBlur}" />
256+
<uui-icon id="icon-add" name="icon-add"></uui-icon>
257+
${this.#renderTagOptions()}
258+
</uui-tag>
259+
`;
260+
}
261+
262+
#renderRemoveButton(tag: string) {
263+
if (this.readonly) return nothing;
264+
return html` <uui-icon name="icon-wrong" @click="${() => this.#delete(tag)}"></uui-icon> `;
265+
}
266+
244267
static override styles = [
245268
css`
246269
#wrapper {
@@ -253,6 +276,7 @@ export class UmbTagsInputElement extends UUIFormControlMixin(UmbLitElement, '')
253276
border: 1px solid var(--uui-color-border);
254277
background-color: var(--uui-input-background-color, var(--uui-color-surface));
255278
flex: 1;
279+
min-height: 40px;
256280
}
257281
258282
#main-tag-wrapper {

src/packages/tags/property-editors/tags/property-editor-ui-tags.element.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export class UmbPropertyEditorUITagsElement extends UmbLitElement implements Umb
2525
return this._value;
2626
}
2727

28+
/**
29+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
30+
* @type {boolean}
31+
* @attr
32+
* @default false
33+
*/
34+
@property({ type: Boolean, reflect: true })
35+
readonly = false;
36+
2837
@state()
2938
private _group?: string;
3039

@@ -62,7 +71,8 @@ export class UmbPropertyEditorUITagsElement extends UmbLitElement implements Umb
6271
group=${ifDefined(this._group)}
6372
.culture=${this._culture}
6473
.items=${this.value}
65-
@change=${this.#onChange}></umb-tags-input>`;
74+
@change=${this.#onChange}
75+
?readonly=${this.readonly}></umb-tags-input>`;
6676
}
6777
}
6878

0 commit comments

Comments
 (0)