From 8434c7d0cbf919532be72e0c86bfed5a3af66877 Mon Sep 17 00:00:00 2001 From: Engiber Lozada <89547469+engijlr@users.noreply.github.com> Date: Thu, 23 Oct 2025 15:49:14 +0200 Subject: [PATCH] Icon Picker: Fix empty selection allowed on mandatory fields and add validation. (#20536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Not show the empty tile when filtering is active. * Added mandatory property to the icon picker. * Avoid deselecting the icon on second click when not showing the empty option. * Extends the form control mixin to the icon picker. * Used super.value. * Support mandatory from settings config. * Removed mandatoryConf. * remove requestUpdate --------- Co-authored-by: Niels Lyngsø --- .../icon-picker-modal.element.ts | 38 +++++++++++++------ .../icon-picker-modal.token.ts | 1 + .../property-editor-ui-icon-picker.element.ts | 37 +++++++++++++----- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/icon-picker-modal/icon-picker-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/icon-picker-modal/icon-picker-modal.element.ts index 0311318845..7227be73a0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/icon-picker-modal/icon-picker-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/icon-picker-modal/icon-picker-modal.element.ts @@ -30,6 +30,9 @@ export class UmbIconPickerModalElement extends UmbModalBaseElement !color.legacy); + @state() + private _isSearching = false; + constructor() { super(); this.consumeContext(UMB_ICON_REGISTRY_CONTEXT, (context) => { @@ -44,8 +47,10 @@ export class UmbIconPickerModalElement extends UmbModalBaseElement 0; this._iconsFiltered = this.#icons.filter((icon) => icon.name.toLowerCase().includes(value.toLowerCase())); } else { + this._isSearching = false; this._iconsFiltered = this.#icons; } } @@ -54,8 +59,12 @@ export class UmbIconPickerModalElement extends UmbModalBaseElement
- { - if (e.key === 'Enter' || e.key === ' ') this.#clearIcon(); - }}> - ${this.renderIcons()} { + if (e.key === 'Enter' || e.key === ' ') this.#clearIcon(); + }}> + + + ` + : nothing} + ${this.renderIcons()} (UmbLitElement, undefined) + implements UmbPropertyEditorUiElement +{ + @property({ type: Boolean }) + mandatory = false; + + protected override firstUpdated(): void { + this.addValidator( + 'valueMissing', + () => 'Icon is required', + () => this.mandatory && !this._icon, + ); + } + @property() - public set value(v: string) { - this._value = v ?? ''; - const parts = this._value.split(' '); + public override set value(v: string) { + const val = v ?? ''; + super.value = val; + + const parts = val.split(' '); if (parts.length === 2) { this._icon = parts[0]; this._color = parts[1].replace('color-', ''); } else { - this._icon = this._value; + this._icon = val; this._color = ''; } } - public get value() { - return this._value; + + public override get value() { + return (super.value as string) ?? ''; } - private _value = ''; @state() private _icon = ''; @@ -53,7 +70,7 @@ export class UmbPropertyEditorUIIconPickerElement extends UmbLitElement implemen icon: this._icon, color: this._color, }, - data: { placeholder: this._placeholderIcon }, + data: { placeholder: this._placeholderIcon, showEmptyOption: !this.mandatory }, }).catch(() => undefined); if (!data) return;