Skip to content

Commit

Permalink
fix(ui): support initial empty value for slider
Browse files Browse the repository at this point in the history
When importing a slider, the initial value is `''`, which throws an
error like `TypeError: "".toFixed is not a function`.

I just handle this edge case.
  • Loading branch information
madeindjs committed Oct 1, 2024
1 parent 1c26d26 commit f7b620e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ui/src/components/core/base/BaseInputRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ const thumbRadius = 9;
const thumb = ref<HTMLElement>();
const slider = ref<HTMLElement>();
const precision = computed(() => Math.ceil(-Math.log10(props.step)));
const displayValue = computed(() => model.value.toFixed(precision.value));
const precision = computed(() => String(props.step).split(".")[1]?.length ?? 0);
const displayValue = computed(() => {
if (typeof model.value !== "number") return "";
return Number(model.value).toFixed(precision.value);
});
const progress = computed(() => {
if (typeof model.value !== "number") return 50;
Expand Down Expand Up @@ -215,6 +218,8 @@ function handleMouseDown(initialEvent: MouseEvent) {
justify-content: center;
padding: 0 4px;
transform: translateX(-50%);
min-width: 12px;
}
.BaseInputRange__popover::after {
Expand Down

0 comments on commit f7b620e

Please sign in to comment.