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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(() => {
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;
});

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
Loading