Skip to content

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

TypeScript

feat(core): add DateTimeInput timePlaceholder prop (#2729) (#3254)

Durvesh Pilankar2581eb48dc18
diff --git a/.changeset/datetimeinput-time-placeholder.md b/.changeset/datetimeinput-time-placeholder.md
new file mode 100644
index 0000000000..ed99e14c46
--- /dev/null
+++ b/.changeset/datetimeinput-time-placeholder.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] DateTimeInput: add a `timePlaceholder` prop to customize the time-portion placeholder (previously hardcoded to "Select a time" with no override). `placeholder` continues to control the date portion; the focused typing hint (e.g. "e.g., 2:30 PM") is unchanged (#2729)
+@durvesh1992
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
index 80eef66633..5d22636d3e 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
+++ b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs
@@ -108,9 +108,15 @@ export const docs = {
{
name: 'placeholder',
type: 'string',
- description: 'Placeholder text shown when no datetime is selected.',
+ description: 'Placeholder text shown in the date portion when no date is selected.',
default: "'Select a date'",
},
+ {
+ name: 'timePlaceholder',
+ type: 'string',
+ description: 'Placeholder text shown in the time portion when no time is selected.',
+ default: "'Select a time'",
+ },
{
name: 'size',
type: "'sm' | 'md' | 'lg'",
@@ -202,7 +208,8 @@ export const docsZh = {
{name: 'hourFormat', type: "'12h' | '24h'", description: "控制显示格式。'12h' 显示 AM/PM;'24h' 使用 24 小时制。", default: "'12h'"},
{name: 'timeIncrement', type: 'number', description: '在时间输入中按箭头键时增减的分钟数。', default: '1'},
{name: 'hasClear', type: 'boolean', description: '当有值时显示清除按钮。', default: 'false'},
- {name: 'placeholder', type: 'string', description: '未选择日期时显示的占位符文本。', default: "'Select a date'"},
+ {name: 'placeholder', type: 'string', description: '日期部分未选择日期时显示的占位符文本。', default: "'Select a date'"},
+ {name: 'timePlaceholder', type: 'string', description: '时间部分未选择时间时显示的占位符文本。', default: "'Select a time'"},
{name: 'size', type: "'sm' | 'md' | 'lg'", description: '输入控件的尺寸。', default: "'md'"},
{name: 'status', type: 'InputStatus', description: '错误、警告或成功状态的状态指示对象,附带消息。'},
{name: 'labelTooltip', type: 'string', description: '通过标签末尾的信息图标显示的提示文本。'},
@@ -249,7 +256,8 @@ export const docsDense = {
hourFormat: "display format. '12h' shows AM/PM; '24h' uses 24-hour",
timeIncrement: 'minutes to add/subtract on arrow keys in time input',
hasClear: 'Shows clear button when datetime is set',
- placeholder: 'placeholder text when empty',
+ placeholder: 'date-portion placeholder when empty',
+ timePlaceholder: 'time-portion placeholder when empty',
size: 'input control size',
status: 'error/warning/success status w/ message',
labelTooltip: 'tooltip text via info icon at label end',
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
index a56ec9dcd0..11a7bb323e 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
@@ -31,6 +31,28 @@ describe('DateTimeInput', () => {
expect(screen.getByPlaceholderText('Pick a date')).toBeInTheDocument();
});
+ it('defaults the time portion placeholder to "Select a time"', () => {
+ render(<DateTimeInput label="Meeting" onChange={() => {}} />);
+ expect(screen.getByPlaceholderText('Select a time')).toBeInTheDocument();
+ });
+
+ it('applies a custom timePlaceholder to the time portion', () => {
+ render(
+ <DateTimeInput
+ label="Meeting"
+ onChange={() => {}}
+ placeholder="Pick a date"
+ timePlaceholder="Pick a time"
+ />,
+ );
+ // Time portion uses the override; date portion keeps its own placeholder.
+ expect(screen.getByPlaceholderText('Pick a time')).toBeInTheDocument();
+ expect(screen.getByPlaceholderText('Pick a date')).toBeInTheDocument();
+ expect(
+ screen.queryByPlaceholderText('Select a time'),
+ ).not.toBeInTheDocument();
+ });
+
it('renders both date and time inputs', () => {
render(<DateTimeInput label="Meeting" onChange={() => {}} />);
expect(screen.getByRole('combobox')).toBeInTheDocument();
@@ -90,9 +112,7 @@ describe('DateTimeInput', () => {
});
it('visually hides label when isLabelHidden is true', () => {
- render(
- <DateTimeInput label="Meeting" isLabelHidden onChange={() => {}} />,
- );
+ render(<DateTimeInput label="Meeting" isLabelHidden onChange={() => {}} />);
const label = screen.getByText('Meeting');
expect(label).toBeInTheDocument();
expect(screen.getByLabelText('Meeting')).toBeInTheDocument();
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 52da6b00cb..c4e25ac72a 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -48,11 +48,7 @@ import {
} from '../Field';
import {Icon} from '../Icon';
import {Spinner} from '../Spinner';
-import {
- Calendar,
- type ISODateString,
- type CalendarHandle,
-} from '../Calendar';
+import {Calendar, type ISODateString, type CalendarHandle} from '../Calendar';
import {useCalendarConstraints} from '../Calendar/hooks';
import {usePopover} from '../Popover';
import {useInputContainer} from '../hooks/useInputContainer';
@@ -278,11 +274,17 @@ export interface DateTimeInputProps extends Omit<
hasClear?: boolean;
/**
- * Placeholder text shown when no date is selected.
+ * Placeholder text shown in the date portion when no date is selected.
* @default "Select a date"
*/
placeholder?: string;
+ /**
+ * Placeholder text shown in the time portion when no time is selected.
+ * @default "Select a time"
+ */
+ timePlaceholder?: string;
+
/**
* The size of the inputs.
* @default 'md'
@@ -385,6 +387,7 @@ export function DateTimeInput({
timeIncrement = 1,
hasClear = false,
placeholder = 'Select a date',
+ timePlaceholder = 'Select a time',
size: sizeProp,
status,
labelTooltip,
@@ -520,12 +523,12 @@ export function DateTimeInput({
return isTimeInRange(parsed, timeMin, timeMax);
}, [timePendingInput, hasSeconds, timeMin, timeMax]);
- const timePlaceholder = useMemo(() => {
+ const resolvedTimePlaceholder = useMemo(() => {
if (isTimeFocused && !timeDisplayValue) {
return hourFormat === '12h' ? 'e.g., 2:30 PM' : 'e.g., 14:30';
}
- return 'Select a time';
- }, [isTimeFocused, timeDisplayValue, hourFormat]);
+ return timePlaceholder;
+ }, [isTimeFocused, timeDisplayValue, hourFormat, timePlaceholder]);
// --- Unified change handler ---
const fireChange = useCallback(
@@ -893,7 +896,7 @@ export function DateTimeInput({
onFocus={handleTimeFocus}
onBlur={handleTimeBlur}
onKeyDown={handleTimeKeyDown}
- placeholder={timePlaceholder}
+ placeholder={resolvedTimePlaceholder}
disabled={isEffectivelyDisabled}
aria-label="Time"
aria-required={isRequired === true ? 'true' : undefined}