Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): fix number format for the input slider #572

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

madeindjs
Copy link
Collaborator

@madeindjs madeindjs commented Sep 28, 2024

When importing a slider, the initial value is '', which throws an error like TypeError: "".toFixed is not a function.

Also, we don't handle the step change correctly, which can leads to RangeError: precision -1 out of range

Screencast.from.2024-09-30.00-55-44.mp4

@madeindjs madeindjs self-assigned this Sep 28, 2024
@madeindjs madeindjs changed the title fix(ui): support initial empty value for slider fix(ui): fix number format for the input slider Sep 29, 2024
const precision = computed(() => String(props.step).split(".")[1]?.length ?? 0);
const displayValue = computed(() =>
Number(model.value).toFixed(precision.value),
);

const progress = computed(() => {
Copy link
Collaborator

@FabienArcellier FabienArcellier Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the behavior of model, I think we should also write this change

const progress = computed(() => {
	const v =
		typeof model.value !== "number" ? Number(model.value) : model.value;

	return ((v - props.min) / (props.max - props.min)) * 100;
});

Avoiding that

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point, the thing is the empty state is always a string because of this

Which make things a bit weird to handle... That's why I choose to put the thumb in the middle.

In fact, I can't display 0 neither because the min could be greater. Thus, I think the best fix is to display nothing in this situation like this :

const displayValue = computed(() => {
	if (typeof model.value !== "number") return "";
	return Number(model.value).toFixed(precision.value);
});

I updated it, well spoted

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the experience is not great for the user.

image

and something like that ? It will render

image

const displayValue = computed(() => {
	const v = model.value !== "" ? model.value : props.min;
	return Number(v).toFixed(precision.value);
});

const progress = computed(() => {
	const v = model.value !== "" ? model.value : props.min;
	return ((v - props.min) / (props.max - props.min)) * 100;
});

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.
@ramedina86 ramedina86 merged commit 1f557a9 into writer:dev Oct 14, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants