hsuanyi-chou / shadcn-ui-expansions

More components built on top of shadcn-ui.
https://shadcnui-expansions.typeart.cc/
MIT License
942 stars 42 forks source link

[feat]: Initial time value for datetime picker #131

Open Sparticuz opened 2 months ago

Sparticuz commented 2 months ago

Feature description

Is there a way to set an initial time value besides 00:00?

Affected component/components

datetime picker

Additional Context

No response

Before submitting

Sparticuz commented 2 months ago

Found it. https://github.com/hsuanyi-chou/shadcn-ui-expansions/blob/b1716a3215ec8f09b2ac9e533aecf09a0e57aec0/components/ui/datetime-picker.tsx#L419

Sparticuz commented 2 months ago

Changing that only changes the initial display, but when I select a day it reverts back to 00:00

hsuanyi-chou commented 2 months ago

Simplely giving the initial value with new Date() The initial value will be the current time.

https://github.com/user-attachments/assets/db76c1fa-2161-4c76-a6ff-61a60ae6fe5b

const DatetimePickerDemo = () => {
  const [date, setDate] = useState<Date | undefined>(new Date());  // <--- here
  return <DateTimePicker value={date} onChange={setDate} />;
};
Sparticuz commented 2 months ago

Hmm, not quite what I was looking for as it is no longer undefined before clicking.