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

[NumberField] snapOnStep prop #1560

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

atomiks
Copy link
Contributor

@atomiks atomiks commented Mar 14, 2025

Closes #1542
Closes #1010

The new snapOnStep prop is a boolean:

  • true: the value is snapped to the nearest step when stepping (incrementing/decrementing). So 1.07 with a step of 1 becomes 2 when incrementing
  • false (new default): the value isn't snapped at all. So 1.07 with a step of 1 becomes 2.07.

Also new behavior for true:

  • If you type a decimal then increment/decrement, it snaps to the nearest regular step, just like largeStep already did.
  • It will snap the nearest step rather than round and unexpectedly go "more" than wanted.

@atomiks atomiks added the component: number field This is the name of the generic UI component, not the React module! label Mar 14, 2025
Copy link

netlify bot commented Mar 14, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0c761a0
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67eb5aadf156590008955eb6
😎 Deploy Preview https://deploy-preview-1560--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@michaldudak
Copy link
Member

Using small or large step with the custom function doesn't work. Decrement doesn't work at all, while increment adds a double value. See https://codesandbox.io/p/devbox/silly-moser-t85lpm?file=%2Fsrc%2FApp.tsx%3A12%2C22&workspaceId=ws_QAeLcZEcDnfGaFA47etEUH

@atomiks
Copy link
Contributor Author

atomiks commented Mar 17, 2025

@michaldudak sandbox is private

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 18, 2025
@michaldudak
Copy link
Member

Try now

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 18, 2025
@atomiks atomiks changed the title [NumberField] stepSnap prop [NumberField] stepBehavior prop Mar 18, 2025
@michaldudak
Copy link
Member

It now works fine with stepBehavior="snap" for small and large steps, but the normal step doesn't snap (10.1 + step = 11.1)

@atomiks
Copy link
Contributor Author

atomiks commented Mar 18, 2025

@michaldudak yeah - hadn't yet changed the implementation after our chat. Just changed the math in a new commit and updated PR description with additional details

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 20, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 21, 2025
@atomiks atomiks changed the title [NumberField] stepBehavior prop [NumberField] snapOnStep prop Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: number field This is the name of the generic UI component, not the React module!
Projects
None yet
2 participants