Skip to content

Commit 6cbd25c

Browse files
fix(ui): improve placeholder handling and label sorting in WdsSelect component
- Enhanced logic to conditionally add a placeholder based on existing options. - Updated label retrieval to ensure proper sorting for multi-selection scenarios. - Refined filtering of options to maintain clarity in the dropdown display.
1 parent 8df9a41 commit 6cbd25c

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/ui/src/wds/WdsSelect.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ const selectOptions = computed<WdsDropdownMenuOption[]>(() => {
150150
(option.value !== undefined ? String(option.value) : ""),
151151
}));
152152
153-
if (!shouldInjectPlaceholder.value) {
153+
const hasEmptyValueOption = normalized.some(
154+
(option) => option.value === PLACEHOLDER_VALUE,
155+
);
156+
157+
const shouldAddPlaceholder =
158+
shouldInjectPlaceholder.value && !hasEmptyValueOption;
159+
160+
if (!shouldAddPlaceholder) {
154161
return normalized;
155162
}
156163
@@ -160,10 +167,7 @@ const selectOptions = computed<WdsDropdownMenuOption[]>(() => {
160167
label: placeholderLabel.value,
161168
isPlaceholder: true,
162169
},
163-
...normalized.filter(
164-
(option) =>
165-
!option.isPlaceholder && option.value !== PLACEHOLDER_VALUE,
166-
),
170+
...normalized.filter((option) => !option.isPlaceholder),
167171
];
168172
});
169173
@@ -200,10 +204,13 @@ const currentLabel = computed(() => {
200204
: String(currentValue.value ?? "");
201205
}
202206
203-
if (!selectedOptions.value.length) return undefined;
207+
const labels = selectedOptions.value.map((o) => o.label).filter(Boolean);
208+
if (!labels.length) return undefined;
209+
210+
const sortedLabels = [...labels].sort((a, b) => a.localeCompare(b));
204211
return props.enableMultiSelection
205-
? selectedOptions.value.map((o) => o.label).join(" / ")
206-
: selectedOptions.value[0].label;
212+
? sortedLabels.join(" / ")
213+
: sortedLabels[0];
207214
});
208215
209216
const currentIcon = computed(() => {

0 commit comments

Comments
 (0)