Skip to content

docs: RFC - Number Field Stepping #8066

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AndrewLeedham
Copy link

RFC for a new prop interval for the NumberField component/hook which influences how incrementing/decrementing works outside of the step prop.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

RFC: N/A

🧢 Your Project:

Onyx Insight


## Detailed Design

Introducing a new prop say `interval` which controls how the field is incremented/decremented across all mediums (buttons, arrow keys, mouse wheel etc.) would allow the value to be optionally specified separately from `step`. This prop should only influence incrementing and decrementing it should not round/clamp the value to the same number of decimal places as `step` does, but `step` should retain this behaviour.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the RFC, we had a discussion about this today and have some questions.

How do we want to define step and interval? I know you've highlighted this in the drawbacks section.

Currently, step is both clamping behaviour and the delta that the arrows move by, impacted by the minValue. This is how native number fields work. https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/step#min_impact_on_step

We have some options. We can either continue with the current definition closely when both are used:
step is clamping behaviour
interval is only how much the arrowup/down moves

Or we could flip the definitions:
step is only how much the arrowup/down moves
interval is clamping behaviour

We'll also probably want to make some errors during development for invalid combinations of the props. These are two we thought might be useful, are there others?

Some other interactions that may exist are the Number formatter options.

NumberField() {
let {
  step,
  interval = step
} = props

// don't forget to include minValue starting point
if (step % interval !== 0) throw?? round (based on format options?)?? totally fine??
if (step > interval) throw??

step will need to stay and will need to behave the same when the other prop isn't there so this is non-breaking. We haven't thought of a better name for interval yet, but perhaps that will come out after determining the definition we want.

An example of usage that might be confusing depending on how we defined these props.

step 10
interval 3
minValue 4
current value is 4
press arrow up -> 14

rounds to 13 (based on minValue impact, valid values are 4, 7, 10, 13, 16) (numberformat options rounding influences this??)
rounds to 15? (don't base on minValue impact when both props are specified? then valid values are 6, 9, 12, 15)

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.

2 participants