Skip to content

Commit a07a047

Browse files
committed
Consistency across the document, media and member pickers
1 parent ac2a14d commit a07a047

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

src/packages/documents/documents/components/input-document/input-document.element.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
7575
* @attr
7676
* @default
7777
*/
78-
@property({ type: String, attribute: 'min-message' })
78+
@property({ type: String, attribute: 'max-message' })
7979
maxMessage = 'This field exceeds the allowed amount of items';
8080

8181
public set selection(ids: Array<string>) {
@@ -126,28 +126,24 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
126126
this.addValidator(
127127
'rangeUnderflow',
128128
() => this.minMessage,
129-
() => !!this.min && this.#pickerContext.getSelection().length < this.min,
129+
() => !!this.min && this.selection.length < this.min,
130130
);
131131

132132
this.addValidator(
133133
'rangeOverflow',
134134
() => this.maxMessage,
135-
() => !!this.max && this.#pickerContext.getSelection().length > this.max,
135+
() => !!this.max && this.selection.length > this.max,
136136
);
137137

138138
this.observe(this.#pickerContext.selection, (selection) => (this.value = selection.join(',')), '_observeSelection');
139139
this.observe(this.#pickerContext.selectedItems, (selectedItems) => (this._items = selectedItems), '_observerItems');
140140
}
141141

142-
protected override getFormElement() {
143-
return undefined;
144-
}
145-
146142
#isDraft(item: UmbDocumentItemModel) {
147143
return item.variants[0]?.state === 'Draft';
148144
}
149145

150-
#pickableFilter: (item: UmbDocumentItemModel) => boolean = (item) => {
146+
#pickableFilter = (item: UmbDocumentItemModel): boolean => {
151147
if (this.allowedContentTypeIds && this.allowedContentTypeIds.length > 0) {
152148
return this.allowedContentTypeIds.includes(item.documentType.unique);
153149
}
@@ -162,7 +158,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
162158
});
163159
}
164160

165-
#removeItem(item: UmbDocumentItemModel) {
161+
#onRemove(item: UmbDocumentItemModel) {
166162
this.#pickerContext.requestRemoveItem(item.unique);
167163
}
168164

@@ -171,7 +167,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
171167
}
172168

173169
#renderAddButton() {
174-
if (this.max === 1 && this.selection.length >= this.max) return;
170+
if (this.selection.length >= this.max) return;
175171
return html`
176172
<uui-button
177173
id="btn-add"
@@ -201,7 +197,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
201197
${this.#renderIcon(item)} ${this.#renderIsTrashed(item)}
202198
<uui-action-bar slot="actions">
203199
${this.#renderOpenButton(item)}
204-
<uui-button @click=${() => this.#removeItem(item)} label=${this.localize.term('general_remove')}></uui-button>
200+
<uui-button @click=${() => this.#onRemove(item)} label=${this.localize.term('general_remove')}></uui-button>
205201
</uui-action-bar>
206202
</uui-ref-node>
207203
`;
@@ -231,7 +227,7 @@ export class UmbInputDocumentElement extends UmbFormControlMixin<string | undefi
231227
static override styles = [
232228
css`
233229
#btn-add {
234-
width: 100%;
230+
display: block;
235231
}
236232
237233
uui-ref-node[drag-placeholder] {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class UmbInputMediaElement extends UmbFormControlMixin<string | undefined
8787
* @attr
8888
* @default
8989
*/
90-
@property({ type: String, attribute: 'min-message' })
90+
@property({ type: String, attribute: 'max-message' })
9191
maxMessage = 'This field exceeds the allowed amount of items';
9292

9393
public set selection(ids: Array<string>) {
@@ -164,20 +164,16 @@ export class UmbInputMediaElement extends UmbFormControlMixin<string | undefined
164164
this.addValidator(
165165
'rangeUnderflow',
166166
() => this.minMessage,
167-
() => !!this.min && this.#pickerContext.getSelection().length < this.min,
167+
() => !!this.min && this.selection.length < this.min,
168168
);
169169
this.addValidator(
170170
'rangeOverflow',
171171
() => this.maxMessage,
172-
() => !!this.max && this.#pickerContext.getSelection().length > this.max,
172+
() => !!this.max && this.selection.length > this.max,
173173
);
174174
}
175175

176-
protected override getFormElement() {
177-
return undefined;
178-
}
179-
180-
#pickableFilter: (item: UmbMediaItemModel) => boolean = (item) => {
176+
#pickableFilter = (item: UmbMediaItemModel): boolean => {
181177
if (this.allowedContentTypeIds && this.allowedContentTypeIds.length > 0) {
182178
return this.allowedContentTypeIds.includes(item.mediaType.unique);
183179
}

src/packages/members/member/components/input-member/input-member.element.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
7474
* @attr
7575
* @default
7676
*/
77-
@property({ type: String, attribute: 'min-message' })
77+
@property({ type: String, attribute: 'max-message' })
7878
maxMessage = 'This field exceeds the allowed amount of items';
7979

8080
public set selection(ids: Array<string>) {
@@ -125,24 +125,20 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
125125
this.addValidator(
126126
'rangeUnderflow',
127127
() => this.minMessage,
128-
() => !!this.min && this.#pickerContext.getSelection().length < this.min,
128+
() => !!this.min && this.selection.length < this.min,
129129
);
130130

131131
this.addValidator(
132132
'rangeOverflow',
133133
() => this.maxMessage,
134-
() => !!this.max && this.#pickerContext.getSelection().length > this.max,
134+
() => !!this.max && this.selection.length > this.max,
135135
);
136136

137137
this.observe(this.#pickerContext.selection, (selection) => (this.value = selection.join(',')), '_observeSelection');
138138
this.observe(this.#pickerContext.selectedItems, (selectedItems) => (this._items = selectedItems), '_observeItems');
139139
}
140140

141-
protected override getFormElement() {
142-
return undefined;
143-
}
144-
145-
#pickableFilter: (item: UmbMemberItemModel) => boolean = (item) => {
141+
#pickableFilter = (item: UmbMemberItemModel): boolean => {
146142
if (this.allowedContentTypeIds && this.allowedContentTypeIds.length > 0) {
147143
return this.allowedContentTypeIds.includes(item.memberType.unique);
148144
}
@@ -156,7 +152,7 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
156152
});
157153
}
158154

159-
#removeItem(item: UmbMemberItemModel) {
155+
#onRemove(item: UmbMemberItemModel) {
160156
this.#pickerContext.requestRemoveItem(item.unique);
161157
}
162158

@@ -178,12 +174,14 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
178174
}
179175

180176
#renderAddButton() {
181-
if (this.max === 1 && this.selection.length >= this.max) return nothing;
182-
return html`<uui-button
183-
id="btn-add"
184-
look="placeholder"
185-
@click=${this.#openPicker}
186-
label=${this.localize.term('general_choose')}></uui-button>`;
177+
if (this.selection.length >= this.max) return nothing;
178+
return html`
179+
<uui-button
180+
id="btn-add"
181+
look="placeholder"
182+
@click=${this.#openPicker}
183+
label=${this.localize.term('general_choose')}></uui-button>
184+
`;
187185
}
188186

189187
#renderItem(item: UmbMemberItemModel) {
@@ -192,7 +190,7 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
192190
<uui-ref-node name=${item.name} id=${item.unique}>
193191
<uui-action-bar slot="actions">
194192
${this.#renderOpenButton(item)}
195-
<uui-button @click=${() => this.#removeItem(item)} label=${this.localize.term('general_remove')}></uui-button>
193+
<uui-button @click=${() => this.#onRemove(item)} label=${this.localize.term('general_remove')}></uui-button>
196194
</uui-action-bar>
197195
</uui-ref-node>
198196
`;
@@ -212,7 +210,7 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
212210
static override styles = [
213211
css`
214212
#btn-add {
215-
width: 100%;
213+
display: block;
216214
}
217215
218216
uui-ref-node[drag-placeholder] {

0 commit comments

Comments
 (0)