Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile/ios): checklist toggle on the first tap

AndreeaCorlaci570be47101af
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index 26d021168b..f0ac3ba111 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -235,6 +235,78 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
document.body.style.setProperty("--code-block-tab-width", codeBlockTabWidth || "4");
}, [codeBlockTabWidth]);
+ // Mobile-only: toggle todo-list checkboxes on the first tap and widen the
+ // hit area so finger taps don't have to land precisely on the ~16px box.
+ // Two problems are being solved:
+ // 1. iOS WKWebView doesn't dispatch `change` on the first tap inside a
+ // contenteditable that isn't focused — users have to tap twice.
+ // 2. The native checkbox is too small to hit reliably with a finger.
+ // We accept any tap whose point lands within ~14px of the checkbox's
+ // bounding box (roughly a 44px touch target, matching Apple HIG), flip
+ // the checkbox, and fire a synthetic change event that CKEditor's
+ // TodoCheckboxChangeObserver picks up.
+ useEffect(() => {
+ const container = containerRef.current;
+ if (!container || !isMobile()) return;
+
+ const HIT_PAD = 14;
+ let tapped: HTMLInputElement | null = null;
+
+ const findCheckboxFromTap = (e: TouchEvent): HTMLInputElement | null => {
+ const target = e.target as HTMLElement | null;
+ if (!target) return null;
+
+ // Direct hit on the checkbox.
+ const direct = target.closest<HTMLInputElement>(
+ '.todo-list__label input[type="checkbox"]'
+ );
+ if (direct) return direct;
+
+ // Near-miss: tap landed on the label or its surroundings. Accept
+ // if the touch point is within HIT_PAD of the checkbox rect.
+ const label = target.closest(".todo-list__label");
+ if (!label) return null;
+ const checkbox = label.querySelector<HTMLInputElement>(
+ 'input[type="checkbox"]'
+ );
+ if (!checkbox) return null;
+
+ const touch = e.touches[0] ?? e.changedTouches[0];
+ if (!touch) return null;
+ const rect = checkbox.getBoundingClientRect();
+ if (
+ touch.clientX >= rect.left - HIT_PAD &&
+ touch.clientX <= rect.right + HIT_PAD &&
+ touch.clientY >= rect.top - HIT_PAD &&
+ touch.clientY <= rect.bottom + HIT_PAD
+ ) {
+ return checkbox;
+ }
+ return null;
+ };
+
+ const onTouchStart = (e: TouchEvent) => {
+ tapped = findCheckboxFromTap(e);
+ };
+
+ const onTouchEnd = (e: TouchEvent) => {
+ if (!tapped) return;
+ const checkbox = tapped;
+ tapped = null;
+ // Suppress the synthesised click so we don't toggle twice.
+ e.preventDefault();
+ checkbox.checked = !checkbox.checked;
+ checkbox.dispatchEvent(new Event("change", { bubbles: true }));
+ };
+
+ container.addEventListener("touchstart", onTouchStart, { passive: true });
+ container.addEventListener("touchend", onTouchEnd, { passive: false });
+ return () => {
+ container.removeEventListener("touchstart", onTouchStart);
+ container.removeEventListener("touchend", onTouchEnd);
+ };
+ }, []);
+
return (
<>
{note && !!templates && <CKEditorWithWatchdog