Skip to content

Commit

Permalink
fix(ui): update slider value if min/max change. WF-4
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Oct 17, 2024
1 parent 46a3132 commit 932c4d5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/ui/src/components/core/base/BaseInputSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
</template>

<script setup lang="ts">
import { computed, PropType, ref, ComponentInstance, toRef } from "vue";
import {
computed,
PropType,
ref,
ComponentInstance,
toRef,
watch,
ComputedRef,
} from "vue";
import BaseInputRangeThumb from "./BaseInputSliderThumb.vue";
import BaseInputSliderLayout from "./BaseInputSliderLayout.vue";
import { useBoundingClientRect } from "@/composables/useBoundingClientRect";
Expand Down Expand Up @@ -61,4 +69,22 @@ const progress = computed(() => {
});
const sliderBoundingRect = useBoundingClientRect(slider);
// update the `value` if the `min` or `max` change and `value` is outside of the range
watch(
() => props.min,
() => {
if (typeof model.value === "number" && model.value < props.min)
model.value = props.min;
},
{ immediate: true },
);
watch(
() => props.max,
() => {
if (typeof model.value === "number" && model.value > props.max)
model.value = props.max;
},
{ immediate: true },
);
</script>
20 changes: 19 additions & 1 deletion src/ui/src/components/core/base/BaseInputSliderRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</template>

<script setup lang="ts">
import { ComponentInstance, computed, PropType, ref, toRef } from "vue";
import { ComponentInstance, computed, PropType, ref, toRef, watch } from "vue";
import BaseInputRangeThumb from "./BaseInputSliderThumb.vue";
import { useBoundingClientRect } from "@/composables/useBoundingClientRect";
import BaseInputSliderLayout from "./BaseInputSliderLayout.vue";
Expand Down Expand Up @@ -99,4 +99,22 @@ const progress = computed(() => {
});
const sliderBoundingRect = useBoundingClientRect(slider);
// update the `value` if the `min` or `max` change and `value` is outside of the range
watch(
() => props.min,
() => {
if (!model.value.some((v) => v < props.min)) return;
model.value = model.value.map((v) => (v < props.min ? props.min : v));
},
{ immediate: true },
);
watch(
() => props.max,
() => {
if (!model.value.some((v) => v > props.max)) return;
model.value = model.value.map((v) => (v > props.max ? props.max : v));
},
{ immediate: true },
);
</script>

0 comments on commit 932c4d5

Please sign in to comment.