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

Number input can change below the "step" with alt key #492

Open
satelllte opened this issue Feb 11, 2024 · 0 comments
Open

Number input can change below the "step" with alt key #492

satelllte opened this issue Feb 11, 2024 · 0 comments

Comments

@satelllte
Copy link

About

Hi Poimandres team 👋

I'm not sure if it's an issue or not, but I didn't find any solution for the cases when I need to keep my number to be integer with a change step of 1. So the workaround I'm using is manual rounding, like this:

const {detail} = useControls({
  detail: {
    value: 2,
    min: 1,
    max: 20,
    step: 1,
  },
});
const detailRounded = Math.round(detail);

If I remove this rounding, go to the scene and change the "detail" slider with Alt + Arrow Up/Down, the scene will crash, because the number changed by $\pm 0.1$ and became non-integer (but has to be integer).

But on the other hand, if this rounding is there and I'm changing the slider with the Alt + Arrow Up/Down, I have to press it 5+ times until the number is rounded over to the next step. And this happens because the Leva number is still changing by 0.1 under the hood, while it gets rounded for my application.

Questions

  1. What's the proper / recommended way to deal with such cases? I didn't find a way how can I change it for controlled input immediately on each change.
  2. Isn't this considered a bug on Leva side to keep the step value in mind and don't get below it? As an option, I'm also thinking maybe it's also worth to introduce a smallStep value for the full control over it?

Links

Links to the use case:

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

No branches or pull requests

1 participant