Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): decouple include-time toggle from initial time in DatePicker (#65522)

Paul D'Ambrae23cf1403414
diff --git a/packages/quill/packages/components/AGENTS.md b/packages/quill/packages/components/AGENTS.md
index 0a488c0aa5bb..ef83487ad3ec 100644
--- a/packages/quill/packages/components/AGENTS.md
+++ b/packages/quill/packages/components/AGENTS.md
@@ -77,14 +77,17 @@ import { DatePicker } from '@posthog/quill-components'
minDate={minDate}
maxDate={new Date()}
dateFormat="MDY" // or 'DMY' | 'YMD'
- showTime // adds hour/minute inputs + an "Include time" toggle
+ showTime // include time in the value initially (hour/minute inputs shown)
+ showTimeToggle // render the "Include time" toggle; defaults to showTime. false = fixed precision
+ onIncludeTimeChange={(includeTime) => ...} // fired when the toggle flips
/>
```
Rules:
- `value`/`onApply` are a single `Date`, not `{ start, end, range }`. Use this for the single-date PostHog callers (currently `LemonCalendarSelect`); reach for `DateTimePicker` only when you need a start→end range.
-- Without `showTime` the applied value is floored to start-of-day. With `showTime`, the "Include time" toggle decides whether the applied value keeps its hour/minute or is floored.
+- `showTime` seeds whether time is included; `showTimeToggle` (defaults to `showTime`) decides whether the "Include time" toggle renders. Set `showTimeToggle={false}` with `showTime` for a fixed time precision (no opt-out); pass `showTimeToggle` alone to start date-only but let the user add time. `onIncludeTimeChange` reports toggle changes so a wrapper can mirror the state (e.g. to update a trigger label).
+- Without time included the applied value is floored to start-of-day; with it, the value keeps its hour/minute.
- Shares the calendar grid and `minDate`/`maxDate` day-granular bounds with `DateTimePicker` (both render `Calendar` from `calendar-grid.tsx`).
- Always a single calendar; there is no `compact`/dual-calendar mode.
diff --git a/packages/quill/packages/components/src/date-picker.stories.tsx b/packages/quill/packages/components/src/date-picker.stories.tsx
index e552748d66f3..820bce916794 100644
--- a/packages/quill/packages/components/src/date-picker.stories.tsx
+++ b/packages/quill/packages/components/src/date-picker.stories.tsx
@@ -40,6 +40,14 @@ export const WithTime: Story = {
},
}
+export const FixedTime: Story = {
+ args: baseArgs,
+ render: () => {
+ const [value, setValue] = React.useState<Date>(initialValue)
+ return <DatePicker value={value} onApply={setValue} showTime showTimeToggle={false} />
+ },
+}
+
export const InPopover: Story = {
args: baseArgs,
render: () => {
diff --git a/packages/quill/packages/components/src/date-picker.test.tsx b/packages/quill/packages/components/src/date-picker.test.tsx
index efddd6b1e98a..017f0ba086fc 100644
--- a/packages/quill/packages/components/src/date-picker.test.tsx
+++ b/packages/quill/packages/components/src/date-picker.test.tsx
@@ -49,6 +49,45 @@ describe('DatePicker', () => {
expect([applied.getDate(), applied.getHours(), applied.getMinutes()]).toEqual([15, 0, 0])
})
+ it.each([
+ ['off by default', {}, false],
+ ['on when showTime is set', { showTime: true }, true],
+ ['on when showTimeToggle is set without showTime', { showTimeToggle: true }, true],
+ ['off when showTimeToggle is false despite showTime', { showTime: true, showTimeToggle: false }, false],
+ ])('renders the include-time toggle %s', (_name, props, expected) => {
+ render(<DatePicker value={VALUE} maxDate={MAX} onApply={jest.fn()} {...props} />)
+
+ expect(!!screen.queryByRole('switch', { name: 'Include time' })).toBe(expected)
+ })
+
+ it('keeps time with no toggle when showTimeToggle is false', async () => {
+ const onApply = jest.fn()
+ render(<DatePicker value={VALUE} maxDate={MAX} showTime showTimeToggle={false} onApply={onApply} />)
+
+ await userEvent.click(screen.getByLabelText('Select Jan 20, 2023'))
+ await userEvent.click(screen.getByLabelText('Apply date'))
+
+ const applied: Date = onApply.mock.calls[0][0]
+ expect([applied.getDate(), applied.getHours(), applied.getMinutes()]).toEqual([20, 10, 30])
+ })
+
+ it('reports toggle changes through onIncludeTimeChange', async () => {
+ const onIncludeTimeChange = jest.fn()
+ render(
+ <DatePicker
+ value={VALUE}
+ maxDate={MAX}
+ showTime
+ onIncludeTimeChange={onIncludeTimeChange}
+ onApply={jest.fn()}
+ />
+ )
+
+ await userEvent.click(screen.getByRole('switch', { name: 'Include time' }))
+
+ expect(onIncludeTimeChange).toHaveBeenCalledWith(false)
+ })
+
it('disables calendar days before minDate', () => {
render(<DatePicker value={VALUE} minDate={new Date(2023, 0, 10)} maxDate={MAX} onApply={jest.fn()} />)
diff --git a/packages/quill/packages/components/src/date-picker.tsx b/packages/quill/packages/components/src/date-picker.tsx
index da8987cf4f3d..64a67f201ad6 100644
--- a/packages/quill/packages/components/src/date-picker.tsx
+++ b/packages/quill/packages/components/src/date-picker.tsx
@@ -29,8 +29,12 @@ export interface DatePickerProps {
dateFormat?: DateFormatOrder
weekStartsOn?: Day
onDateTimeSettings?: () => void
- /** Show hour/minute inputs and an "Include time" toggle. When off, the value is floored to the start of the day. */
+ /** Include time in the value initially. When off, the value is floored to the start of the day. */
showTime?: boolean
+ /** Render the "Include time" toggle so the user can switch time on and off. Defaults to `showTime`. Set false for a fixed precision. */
+ showTimeToggle?: boolean
+ /** Fired when the "Include time" toggle changes. */
+ onIncludeTimeChange?: (includeTime: boolean) => void
className?: string
}
@@ -45,6 +49,8 @@ export function DatePicker({
weekStartsOn,
onDateTimeSettings,
showTime = false,
+ showTimeToggle = showTime,
+ onIncludeTimeChange,
className,
}: DatePickerProps): React.ReactElement {
const maxDate = maxDateProp ?? new Date()
@@ -77,6 +83,11 @@ export function DatePicker({
setViewing(new Date(getYear(clamped), getMonth(clamped), 1))
}
+ const handleIncludeTimeChange = (next: boolean): void => {
+ setIncludeTime(next)
+ onIncludeTimeChange?.(next)
+ }
+
const handleApply = (): void => {
onApply(includeTime ? selected : startOfDay(selected))
}
@@ -144,11 +155,11 @@ export function DatePicker({
/>
</div>
- {showTime && (
+ {showTimeToggle && (
<div className="flex items-center gap-2 px-3 py-1.5 border-t border-border">
<Switch
checked={includeTime}
- onCheckedChange={setIncludeTime}
+ onCheckedChange={handleIncludeTimeChange}
aria-label="Include time"
id={includeTimeId}
data-attr="date-picker-include-time"