Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b13465e

Browse files
fix calendar doubleclick event + added singleClick event
1 parent 1053d19 commit b13465e

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

‎client/packages/lowcoder-comps/src/comps/calendarComp/calendarComp.tsx‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ let CalendarBasicComp = (function () {
268268
const ref = createRef<HTMLDivElement>();
269269
const editEvent = useRef<EventInput>();
270270
const initData = useRef<boolean>(false);
271+
const clickTimeout = useRef<NodeJS.Timeout | null>(null);
271272
const [form] = Form.useForm();
272273
const [left, setLeft] = useState<number | undefined>(undefined);
273274
const [licensed, setLicensed] = useState<boolean>(props.licenseKey !== "");
@@ -370,6 +371,15 @@ let CalendarBasicComp = (function () {
370371
initData.current = true;
371372
}
372373
}, [JSON.stringify(initialEvents), comp?.children?.comp?.children?.initialData]);
374+
375+
// Cleanup timeout on unmount
376+
useEffect(() => {
377+
return () => {
378+
if (clickTimeout.current) {
379+
clearTimeout(clickTimeout.current);
380+
}
381+
};
382+
}, []);
373383

374384
const resources = useMemo(() => props.resources.value, [props.resources.value]);
375385

@@ -850,22 +860,30 @@ let CalendarBasicComp = (function () {
850860
handleEventDataChange,
851861
]);
852862

863+
const handleSingleClick = useCallback(() => {
864+
// Prevent double click from triggering the event
865+
// Use a timeout to debounce rapid clicks
866+
if (clickTimeout.current) {
867+
clearTimeout(clickTimeout.current);
868+
clickTimeout.current = null;
869+
return; // This was a double click, don't trigger
870+
}
871+
872+
clickTimeout.current = setTimeout(() => {
873+
props.onEvent('click');
874+
clickTimeout.current = null;
875+
}, 150); // Small delay to catch double clicks
876+
}, [props.onEvent]);
877+
853878
const handleDbClick = useCallback(() => {
854-
const event = props.updatedEventsData.find(
855-
(item: EventType) => item.id === editEvent.current?.id
856-
) as EventType;
857879
if (!props.editable || !editEvent.current) {
858880
return;
859881
}
860-
if (event) {
861-
showModal(event, true);
882+
if (onEventVal && onEventVal.some((e: any) => e.name === 'doubleClick')) {
883+
// Check if 'doubleClick' is included in the array
884+
props.onEvent('doubleClick');
862885
} else {
863-
if (onEventVal && onEventVal.some((e: any) => e.name === 'doubleClick')) {
864-
// Check if 'doubleClick' is included in the array
865-
props.onEvent('doubleClick');
866-
} else {
867-
showModal(editEvent.current as EventType, false);
868-
}
886+
showModal(editEvent.current as EventType, false);
869887
}
870888
}, [
871889
editEvent,
@@ -974,6 +992,9 @@ let CalendarBasicComp = (function () {
974992
allDaySlot={props.showAllDay}
975993
eventContent={renderEventContent}
976994
select={(info) => handleCreate(info)}
995+
dateClick={() => {
996+
handleSingleClick();
997+
}}
977998
eventClick={(info) => {
978999
const event = events.find(
9791000
(item: EventInput) => item.id === info.event.id
@@ -982,6 +1003,7 @@ let CalendarBasicComp = (function () {
9821003
setTimeout(() => {
9831004
editEvent.current = undefined;
9841005
}, 500);
1006+
handleSingleClick();
9851007
}}
9861008
moreLinkClick={(info) => {
9871009
let left = 0;

‎client/packages/lowcoder/src/comps/controls/eventHandlerControl.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ export const DragEventHandlerControl = eventHandlerControl([
737737

738738
export const CalendarEventHandlerControl = eventHandlerControl([
739739
changeEvent,
740+
clickEvent,
740741
doubleClickEvent,
741742
] as const);
742743

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /