add support for custom text fields

This commit is contained in:
Hayden 2022-10-15 21:41:27 -08:00
parent 57f9372e49
commit 434f1fa411
11 changed files with 384 additions and 38 deletions

View file

@ -50,17 +50,40 @@
const selectedIdx = ref(-1);
const internalSelected = useVModel(props, "modelValue", emit);
const internalValue = useVModel(props, "value", emit);
watch(selectedIdx, newVal => {
internalSelected.value = props.items[newVal];
});
watch(internalSelected, newVal => {
watch(selectedIdx, newVal => {
if (props.valueKey) {
emit("update:value", newVal[props.valueKey]);
internalValue.value = props.items[newVal][props.valueKey];
}
});
watch(
internalSelected,
() => {
const idx = props.items.findIndex(item => compare(item, internalSelected.value));
selectedIdx.value = idx;
},
{
immediate: true,
}
);
watch(
internalValue,
() => {
const idx = props.items.findIndex(item => compare(item[props.valueKey], internalValue.value));
selectedIdx.value = idx;
},
{
immediate: true,
}
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function compare(a: any, b: any): boolean {
if (a === b) {
@ -73,15 +96,4 @@
return JSON.stringify(a) === JSON.stringify(b);
}
watch(
internalSelected,
() => {
const idx = props.items.findIndex(item => compare(item, internalSelected.value));
selectedIdx.value = idx;
},
{
immediate: true,
}
);
</script>