Alert dialog example

Delete a local draft explicitly.

Cancel receives focus first. Only the explicit Delete draft action removes the local draft; no service deletion is implied.

Complete React client module · MIT · Next.js and Vite

Interactive example

Delete a local draft explicitly

Cancel receives focus first. Only the explicit Delete draft action removes the local draft; no service deletion is implied.

Keyboard

  • Opening places focus on Cancel. Tab stays within the modal confirmation.
  • Escape cancels and returns focus. Clicking outside does not dismiss.
  • Delete draft runs the supplied callback and closes after it returns.

States covered

  • Cancel-first focus
  • explicit destructive confirmation
  • synchronous host callback
  • focus restoration
  • local result

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-alert-dialog-delete.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useRef,useState} from 'react';
import {Button,UIProvider} from '@bld8/ui';
import {AlertDialog} from '@bld8/ui/alert-dialog';
export default function DeleteDraftExample(){
  const [deleted,setDeleted]=useState(false),restore=useRef<HTMLButtonElement>(null);
  return <UIProvider><div style={{display:'grid',gap:16,maxWidth:460}}><strong>Release note draft</strong><p>{deleted?'This local draft has been deleted.':'A draft awaiting review.'}</p>
    <AlertDialog trigger={<Button variant="danger" disabled={deleted}>Delete draft</Button>} title="Delete this draft?" description="The local Release note draft will be removed from this example. This action cannot be undone here." confirmLabel="Delete draft" destructive finalFocus={()=>deleted?restore.current:true} onConfirm={()=>setDeleted(true)}/>
    <Button ref={restore} variant="secondary" onClick={()=>setDeleted(false)} disabled={!deleted}>Create another draft</Button><p role="status">{deleted?'Draft deleted locally':'Draft available'}</p>
  </div></UIProvider>;
}