@@ -28,6 +28,24 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
2828 [ onEditEvent ]
2929 ) ;
3030
31+ const invokeCreate = useCallback (
32+ ( slotInfo : { start : Date ; end : Date ; action : string } ) => {
33+ const action = onCreateEvent ;
34+
35+ if ( action ?. canExecute && editable ?. value === true ) {
36+ // An event is considered "all day" when the duration is an exact multiple of 24 hours.
37+ const isAllDay =
38+ ( ( slotInfo . end . getTime ( ) - slotInfo . start . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ) % 1 === 0 ;
39+ action . execute ( {
40+ startDate : slotInfo . start ,
41+ endDate : slotInfo . end ,
42+ allDay : isAllDay
43+ } ) ;
44+ }
45+ } ,
46+ [ onCreateEvent , editable ]
47+ ) ;
48+
3149 // https://github.com/jquense/react-big-calendar/blob/master/stories/props/onSelectEvent.stories.js
3250 const handleSelectEvent = useCallback (
3351 ( event : CalendarEvent ) => {
@@ -55,13 +73,17 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
5573
5674 clickRef . current = setTimeout ( ( ) => {
5775 invokeEdit ( event ) ;
76+ setSelected ( event ) ;
5877 } , 250 ) ;
5978 } ,
6079 [ invokeEdit ]
6180 ) ;
6281
6382 const handleKeyPressEvent = useCallback (
6483 ( event : CalendarEvent , e : any ) => {
84+ if ( clickRef ?. current ) {
85+ clearTimeout ( clickRef . current ) ;
86+ }
6587 if ( e . key === "Enter" && selected ?. item . id === event . item . id ) {
6688 invokeEdit ( event ) ;
6789 }
@@ -71,20 +93,12 @@ export function useCalendarEvents(props: CalendarContainerProps): CalendarEventH
7193
7294 const handleCreateEvent = useCallback (
7395 ( slotInfo : { start : Date ; end : Date ; action : string } ) => {
74- const action = onCreateEvent ;
75-
76- if ( action ?. canExecute && editable ?. value === true ) {
77- // is all day : if the difference between start and end is a multiple of 24 hours
78- const isAllday =
79- ( ( slotInfo . end . getTime ( ) - slotInfo . start . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ) % 1 === 0 ;
80- action ?. execute ( {
81- startDate : slotInfo . start ,
82- endDate : slotInfo . end ,
83- allDay : isAllday
84- } ) ;
96+ setSelected ( null ) ;
97+ if ( ! selected ) {
98+ invokeCreate ( slotInfo ) ;
8599 }
86100 } ,
87- [ onCreateEvent , editable ]
101+ [ invokeCreate , selected ]
88102 ) ;
89103
90104 const handleEventDropOrResize = useCallback (
0 commit comments