Skip to content

fix(core): clamp DateTimeInput timeIncrement to a 1–59 integer#3251

Open
durvesh1992 wants to merge 1 commit into
facebook:mainfrom
durvesh1992:fix/datetimeinput-time-increment-clamp
Open

fix(core): clamp DateTimeInput timeIncrement to a 1–59 integer#3251
durvesh1992 wants to merge 1 commit into
facebook:mainfrom
durvesh1992:fix/datetimeinput-time-increment-clamp

Conversation

@durvesh1992

Copy link
Copy Markdown
Contributor

Summary

DateTimeInput's timeIncrement (minute step for arrow-key time stepping) was typed number with no runtime validation. From the Properties tab — or any caller — you could pass:

  • negatives (-5)
  • fractions (2.5)
  • huge values (20000000), which don't roll over into the date and just do nothing useful

This rounds and clamps the value to a positive integer in the 1–59 range at render time, with a dev-only console.warn when an out-of-range value is passed:

const roundedIncrement = Math.round(timeIncrementProp);
const timeIncrement = Number.isFinite(roundedIncrement)
  ? Math.min(59, Math.max(1, roundedIncrement))
  : 1;

So -5 → 1, 2.5 → 3, 20000000 → 59, and valid values (1/5/10/15/30) pass through untouched.

Test plan

  • Added 4 unit tests covering negative, fractional, huge, and valid in-range values (warn + clamp). 42/42 DateTimeInput tests pass.
  • Updated the prop JSDoc and DateTimeInput.doc.mjs description to document the constraint.

Note: rendering a proper number input with min/max/step in the docsite Properties control (issue option 2) is a separate docsite-side change, not included here.

Closes #2725

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 29, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this. Reading through the issue I'm thinking it might be better to use the first solution instead and type this as a literal union with sensible values to prevent unusual values for the increment. Similar to the other issue with 1 | 2 calendars, we should also check the docsite properties panel can represent these unions with a number selector instead of a number input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

2 participants