Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/components/src/components/DateInput/DateInput.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ and pass the `locale` prop.
You can also use the date field to select both date and time.

<Story of={Stories.DateTime} />

## Paste date and time

Use this example for date fields where users may paste values instead of typing them.

<Story of={Stories.PasteDateTime} />
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {
now,
today,
parseDate,
parseDateTime,
getLocalTimeZone,
parseZonedDateTime,
type CalendarDateTime,
} from '@internationalized/date';
import { IconCalendarO16 } from '@koobiq/react-icons';
import type { Meta, StoryObj } from '@storybook/react';
Expand Down Expand Up @@ -173,3 +175,44 @@ export const DateTime: Story = {
);
},
};

export const PasteDateTime: Story = {
name: 'Paste date and time',
render: function Render() {
const [value, setValue] = useState<CalendarDateTime | null>(null);
const [error, setError] = useState<string | null>(null);

return (
<DateInput
hideTimeZone
hourCycle={24}
granularity="minute"
label="Date and time"
value={value}
onChange={(newValue) => {
setValue(newValue);
setError(null);
}}
isInvalid={Boolean(error)}
errorMessage={error}
caption="Paste ISO value: 2026-06-15T14:30"
slotProps={{
inputDate: {
onPaste: (event) => {
event.preventDefault();

const text = event.clipboardData.getData('text/plain').trim();

try {
setValue(parseDateTime(text));
setError(null);
} catch {
setError('Use date and time format: YYYY-MM-DDTHH:mm');
}
},
},
}}
/>
);
},
};
Loading