Property Editors: Hide "add button" when maximum configuration is 1 (fixes #20407) (#20738)

Hide add button when max 1

Co-authored-by: Lan Nguyen Thuy <lnt@umbraco.dk>
This commit is contained in:
NguyenThuyLan
2025-11-05 19:12:04 +07:00
committed by GitHub
parent 297c5d3824
commit 72d7ed438f
5 changed files with 10 additions and 6 deletions

View File

@@ -198,6 +198,9 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen
@state() @state()
private _isReadOnly: boolean = false; private _isReadOnly: boolean = false;
@state()
private _limitMax?: number;
constructor() { constructor() {
super(); super();
@@ -294,6 +297,7 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen
} }
async #setupRangeValidation(rangeLimit: UmbNumberRangeValueType | undefined) { async #setupRangeValidation(rangeLimit: UmbNumberRangeValueType | undefined) {
this._limitMax = rangeLimit?.max;
if (this.#rangeUnderflowValidator) { if (this.#rangeUnderflowValidator) {
this.removeValidator(this.#rangeUnderflowValidator); this.removeValidator(this.#rangeUnderflowValidator);
this.#rangeUnderflowValidator = undefined; this.#rangeUnderflowValidator = undefined;
@@ -408,6 +412,7 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen
} }
#renderCreateButtonGroup() { #renderCreateButtonGroup() {
if (this._limitMax === 1 && this._layoutEntries.length > 0) return nothing;
if (this._areaKey === null || this._layoutEntries.length === 0) { if (this._areaKey === null || this._layoutEntries.length === 0) {
return html` <uui-button-group id="createButton"> return html` <uui-button-group id="createButton">
${this.#renderCreateButton()} ${this.#renderPasteButton()} ${this.#renderCreateButton()} ${this.#renderPasteButton()}

View File

@@ -394,11 +394,8 @@ export class UmbPropertyEditorUIBlockListElement
} }
#renderCreateButtonGroup() { #renderCreateButtonGroup() {
if (this.readonly && this._layouts.length > 0) { if (this._layouts.length > 0 && (this._limitMax === 1 || this.readonly)) return nothing;
return nothing; return html`<uui-button-group>${this.#renderCreateButton()}${this.#renderPasteButton()}</uui-button-group>`;
} else {
return html`<uui-button-group>${this.#renderCreateButton()}${this.#renderPasteButton()}</uui-button-group>`;
}
} }
#renderInlineCreateButton(index: number) { #renderInlineCreateButton(index: number) {

View File

@@ -221,6 +221,7 @@ export class UmbInputMultipleTextStringElement extends UmbFormControlMixin<undef
#renderAddButton() { #renderAddButton() {
if (this.disabled || this.readonly) return nothing; if (this.disabled || this.readonly) return nothing;
if (this.max === 1 && this._items.length > 0) return nothing;
return html` return html`
<uui-button <uui-button
color="default" color="default"

View File

@@ -214,7 +214,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
} }
#renderAddButton() { #renderAddButton() {
if (this.selection.length >= this.max) return nothing; if (this.selection.length > 0 && this.max === 1) return nothing;
if (this.readonly && this.selection.length > 0) { if (this.readonly && this.selection.length > 0) {
return nothing; return nothing;
} else { } else {

View File

@@ -388,6 +388,7 @@ export class UmbInputRichMediaElement extends UmbFormControlMixin<
#renderAddButton() { #renderAddButton() {
if (this.readonly) return nothing; if (this.readonly) return nothing;
if (this.max === 1 && this._cards.length > 0) return nothing;
return html` return html`
<uui-button <uui-button
id="btn-add" id="btn-add"