From 0eeda2fb7ca1c9fd26a6e69e189ffbca360ce493 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Sat, 18 Nov 2023 11:41:21 +0200 Subject: [PATCH] Make the default value a required prop for ScaleLineInput ref #480 --- src/components/ScaleLineInput.vue | 27 ++++++++++++++----- .../generation/CombinationProductSet.vue | 14 ++++------ .../modals/generation/CrossPolytope.vue | 14 +++++----- .../modals/generation/EqualTemperament.vue | 12 +++------ src/components/modals/generation/MosScale.vue | 16 +++++------ src/components/modals/generation/RankTwo.vue | 11 +++++--- .../modals/generation/SpanLattice.vue | 12 +++------ .../modals/generation/SummonOctaplex.vue | 14 +++++----- .../modals/modification/MergeOffset.vue | 10 +++++-- src/constants.ts | 11 ++++++++ 10 files changed, 77 insertions(+), 64 deletions(-) diff --git a/src/components/ScaleLineInput.vue b/src/components/ScaleLineInput.vue index 92b4ee02..ed969c39 100644 --- a/src/components/ScaleLineInput.vue +++ b/src/components/ScaleLineInput.vue @@ -6,23 +6,36 @@ import { ref, watch } from "vue"; const props = defineProps<{ modelValue: string; + defaultValue: Interval; placeholder?: string; - defaultValue?: Interval; }>(); const emit = defineEmits(["update:value", "update:modelValue"]); const element = ref(null); -const defaultValue = - props.defaultValue === undefined - ? parseLine(props.modelValue || "1/1", DEFAULT_NUMBER_OF_COMPONENTS) - : props.defaultValue; const [value, error] = computedAndError( () => parseLine(props.modelValue, DEFAULT_NUMBER_OF_COMPONENTS), - defaultValue + props.defaultValue ); watch(value, (newValue) => emit("update:value", newValue), { immediate: true }); -watch(error, (newError) => element.value!.setCustomValidity(newError)); +watch( + element, + (newElement) => { + if (newElement) { + newElement.setCustomValidity(error.value); + } + }, + { immediate: true } +); +watch( + error, + (newError) => { + if (element.value) { + element.value.setCustomValidity(newError); + } + }, + { immediate: true } +);