Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): type DateTimeInput timeIncrement as literal union per review (#2725) (#3802)

Cindy Zhang7c661aa550ae
diff --git a/.changeset/datetimeinput-time-increment-clamp.md b/.changeset/datetimeinput-time-increment-clamp.md
new file mode 100644
index 0000000000..353996d7e0
--- /dev/null
+++ b/.changeset/datetimeinput-time-increment-clamp.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] DateTimeInput: `timeIncrement` is now typed as a literal union of sensible increments (`1 | 5 | 10 | 15 | 30`) instead of an open `number`, so negatives, fractions, and absurd values are rejected at the type level rather than silently accepted. Adds an exported `DateTimeInputTimeIncrement` type (#2725)
+@durvesh1992
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
index ee9ef5f0e0..585434a969 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
+++ b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
@@ -118,7 +118,7 @@ export const docs = {
},
{
name: 'timeIncrement',
- type: 'number',
+ type: '1 | 5 | 10 | 15 | 30',
description:
'Minutes to add or subtract when using arrow keys in the time input.',
default: '1',
@@ -413,7 +413,7 @@ export const docsZh = {
},
{
name: 'timeIncrement',
- type: 'number',
+ type: '1 | 5 | 10 | 15 | 30',
description: '在时间输入中按箭头键时增减的分钟数。',
default: '1',
},
@@ -469,6 +469,7 @@ export const docsZh = {
description:
'用于布局自定义的 StyleX 样式。必须是 stylex.create() 的值。',
},
+
],
theming: {
targets: [
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
index a093aac811..8963fc571b 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
@@ -747,4 +747,43 @@ describe('DateTimeInput', () => {
expect(timeInput).toHaveAttribute('placeholder', 'Select a time');
});
});
+
+ describe('timeIncrement', () => {
+ it('steps the time by timeIncrement minutes on ArrowUp', () => {
+ const onChange = vi.fn();
+ render(
+ <DateTimeInput
+ label="Meeting"
+ value={'2026-03-15T14:30' as ISODateTimeString}
+ timeIncrement={15}
+ onChange={onChange}
+ />,
+ );
+
+ const timeInput = screen.getByLabelText('Meeting time');
+ fireEvent.keyDown(timeInput, {key: 'ArrowUp'});
+
+ // 14:30 + 15min increment = 14:45
+ expect(onChange).toHaveBeenCalledTimes(1);
+ expect(onChange.mock.calls[0][0]).toContain('14:45');
+ });
+
+ it('defaults to a 1-minute increment', () => {
+ const onChange = vi.fn();
+ render(
+ <DateTimeInput
+ label="Meeting"
+ value={'2026-03-15T14:30' as ISODateTimeString}
+ onChange={onChange}
+ />,
+ );
+
+ const timeInput = screen.getByLabelText('Meeting time');
+ fireEvent.keyDown(timeInput, {key: 'ArrowUp'});
+
+ // 14:30 + default 1min = 14:31
+ expect(onChange).toHaveBeenCalledTimes(1);
+ expect(onChange.mock.calls[0][0]).toContain('14:31');
+ });
+ });
});
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 6b604e8719..4f9cf9cb22 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -86,6 +86,9 @@ export type DateTimeInputHourFormat = '12h' | '24h';
export type DateTimeInputSize = 'sm' | 'md' | 'lg';
+/** Supported minute increments for arrow-key stepping of the time field. */
+export type DateTimeInputTimeIncrement = 1 | 5 | 10 | 15 | 30;
+
export type {
InputStatus as DateTimeInputStatus,
InputStatusType as DateTimeInputStatusType,
@@ -287,10 +290,11 @@ export interface DateTimeInputProps extends Omit<
hourFormat?: DateTimeInputHourFormat;
/**
- * Time increment in minutes when using arrow keys in the time input.
+ * Minutes added or subtracted when stepping the time field with the arrow
+ * keys. Constrained to a set of sensible increments.
* @default 1
*/
- timeIncrement?: number;
+ timeIncrement?: DateTimeInputTimeIncrement;
/**
* Whether to show a clear button when a value is set.
diff --git a/packages/core/src/DateTimeInput/index.ts b/packages/core/src/DateTimeInput/index.ts
index 94725fa7f1..8ae8292da4 100644
--- a/packages/core/src/DateTimeInput/index.ts
+++ b/packages/core/src/DateTimeInput/index.ts
@@ -14,6 +14,7 @@ export type {
DateTimeInputProps,
DateTimeInputSize,
DateTimeInputHourFormat,
+ DateTimeInputTimeIncrement,
DateTimeInputStatus,
DateTimeInputStatusType,
ISODateTimeString,