Confirm dialog

Asks before something that can't be undone. One dialog for the whole app, opened with a call that waits for the answer, so the code that asks reads top to bottom.

Examples

 

Set up

The provider renders the dialog and gives everything below it the confirm call.

<!-- Once, in the root layout -->
<ConfirmDialogProvider>
	{@render children()}
</ConfirmDialogProvider>

Asking

const confirm = getConfirm();

async function remove() {
	const ok = await confirm({
		title: 'Delete project',
		message: 'Starefoss ledning, its 14 missions and all their data are deleted.',
		confirmText: 'Delete project',
		variant: 'danger',
		confirmInput: project.name,
		pendingText: 'Deleting...',
		action: () => deleteProject(project.id),
	});
	if (ok) goto('/projects');
}

Rules

  • Only before something that can’t be undone or is costly to redo. Asking every time trains people to click through.
  • The title is the question or the action; the message says what will happen, with the names and numbers.
  • The confirm button repeats the action ("Delete project"), so it reads on its own. Cancel stays Cancel, or says what is kept.
  • danger for deletes and anything else that can’t be undone, primary otherwise.
  • Type to confirm only for the worst: a project, an account, an organisation. Matching ignores case and stray spaces.
  • Pass the work as action and the button shows the pending text while it runs. The dialog stays open if it fails.