Skip to content
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,23 @@
this._matches = data.items;
}

#onKeydown(e: KeyboardEvent) {
#onKeydown(e: KeyboardEvent, idx: number) {
//Prevent tab away if there is a input.
if (e.key === 'Tab' && (this._tagInput.value as string).trim().length && !this._matches.length) {
e.preventDefault();
this.#createTag();
return;
}

//To be able to get out of the input
if (e.key === 'Tab' && !(this._tagInput.value as string).trim().length) return;

if (e.key === 'Backspace') {
e.preventDefault();
console.log('DELETE TAG:', this.#items[idx]);
this.#delete(this.#items[idx]);
}

Check warning on line 97 in src/Umbraco.Web.UI.Client/src/packages/tags/components/tags-input/tags-input.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

UmbTagsInputElement.onKeydown increases in cyclomatic complexity from 11 to 14, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
if (e.key === 'Enter') {
this.#createTag();
return;
Expand Down Expand Up @@ -208,9 +218,9 @@
}

#enteredTags() {
return html` ${this.items.map((tag) => {
return html` ${this.items.map((tag, index) => {
return html`
<uui-tag class="tag">
<uui-tag class="tag" tabindex="0" @keydown="${(e: KeyboardEvent) => this.#onKeydown(e, index)}">
<span>${tag}</span>
${this.#renderRemoveButton(tag)}
</uui-tag>
Expand Down
Loading