Skip to content

Commit

Permalink
push selected option to end
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicBlueberry committed Nov 13, 2023
1 parent 0b212d3 commit b1d6af4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion client/src/components/Form/Elements/FormSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ const emit = defineEmits<{
(e: "input", value: SelectValue | Array<SelectValue>): void;
}>();
/**
* When there are more options than this, push selected options to the end
*/
const optionReorderThreshold = 8;
const reorderedOptions = computed(() => {
if (props.options.length <= optionReorderThreshold) {
return props.options;
} else {
const selectedOptions: SelectOption[] = [];
const unselectedOptions: SelectOption[] = [];
props.options.forEach((option) => {
if (selectedValues.value.includes(option.value)) {
selectedOptions.push(option);
} else {
unselectedOptions.push(option);
}
});
return [...unselectedOptions, ...selectedOptions];
}
});
/**
* Configure deselect label
*/
Expand Down Expand Up @@ -141,7 +165,7 @@ onMounted(() => {
:deselect-label="deselectLabel"
label="label"
:multiple="multiple"
:options="props.options"
:options="reorderedOptions"
:placeholder="placeholder"
:selected-label="selectedLabel"
select-label="Click to select"
Expand Down

0 comments on commit b1d6af4

Please sign in to comment.