diff --git a/apps/web/src/views/card/components/NewChecklistForm.tsx b/apps/web/src/views/card/components/NewChecklistForm.tsx index 4d15865d..3eb69bcb 100644 --- a/apps/web/src/views/card/components/NewChecklistForm.tsx +++ b/apps/web/src/views/card/components/NewChecklistForm.tsx @@ -17,7 +17,7 @@ interface NewChecklistFormInput { } export function NewChecklistForm({ cardPublicId }: { cardPublicId: string }) { - const { closeModal } = useModal(); + const { closeModal, setModalState } = useModal(); const { showPopup } = usePopup(); const utils = api.useUtils(); @@ -56,6 +56,9 @@ export function NewChecklistForm({ cardPublicId }: { cardPublicId: string }) { }); return { previous }; }, + onSuccess: (data) => { + setModalState("ADD_CHECKLIST", { createdChecklistId: data.publicId }); + }, onError: (_error, vars, ctx) => { if (ctx?.previous) utils.card.byId.setData( diff --git a/apps/web/src/views/card/components/NewChecklistItemForm.tsx b/apps/web/src/views/card/components/NewChecklistItemForm.tsx index 04511fa5..5c52bc5a 100644 --- a/apps/web/src/views/card/components/NewChecklistItemForm.tsx +++ b/apps/web/src/views/card/components/NewChecklistItemForm.tsx @@ -40,17 +40,12 @@ const NewChecklistItemForm = ({ const refocusEditable = () => { const el = editableRef.current; if (!el) return; + el.focus(); + + // hack to ensure the input is focused after creating new checklist item setTimeout(() => { el.focus(); - const range = document.createRange(); - range.selectNodeContents(el); - range.collapse(false); - const sel = window.getSelection(); - if (sel) { - sel.removeAllRanges(); - sel.addRange(range); - } - }, 0); + }, 100); }; const addChecklistItemMutation = api.checklist.createItem.useMutation({ @@ -150,6 +145,8 @@ const NewChecklistItemForm = ({
( @@ -192,6 +198,17 @@ export default function CardPage() { }); }; + // Open the new item form after creating a new checklist + useEffect(() => { + if (!card) return; + const state = getModalState("ADD_CHECKLIST"); + const createdId: string | undefined = state?.createdChecklistId; + if (createdId) { + setActiveChecklistForm(createdId); + clearModalState("ADD_CHECKLIST"); + } + }, [card, getModalState, clearModalState]); + if (!cardId) return <>; return (