Overlays

Dialog.

A focused task with a clear way back.

LIVE PREVIEWTry it. It works.

Install the source

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/dialog.json

Registry setup · Examples · API and behavior · Open the playground

COMPLETE EXAMPLES

Use it in context.

Each example includes its imports, data and state. The preview runs that same source. Include the stylesheet once in your application.

Edit a local title

The modal owns a short draft; Save updates in-memory content before dismissal.

Loads this example when you need it.

Keyboard

  • Tab stays inside the open dialog.
  • Escape dismisses and restores trigger focus.

States covered

  • Closed
  • Editing
  • Locally saved

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-basic-dialog.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 {useState} from 'react';
import {Button,Dialog,DialogClose,Field,Input,UIProvider} from '@bld8/ui';
import '@bld8/ui/styles.css';
export default function DialogExample(){const [open,setOpen]=useState(false),[title,setTitle]=useState('Interface review'),[draft,setDraft]=useState(title);return <UIProvider><p>Current title: {title}</p><Dialog title="Edit example title" description="Changes remain in this example." open={open} onOpenChange={next=>{setOpen(next);if(next)setDraft(title);}} trigger={<Button>Edit example title</Button>}><Field label="Example title"><Input value={draft} onChange={event=>setDraft(event.target.value)}/></Field><Button disabled={!draft.trim()} onClick={()=>{setTitle(draft.trim());setOpen(false);}}>Save example title</Button><DialogClose>Discard example draft</DialogClose></Dialog></UIProvider>;}

Independent themes and nested overlays

Two workspaces share one document with independent tokens, direction and motion. Dialogs, nested choices and an external portal inherit the owning workspace.

Keyboard

  • Open either workspace dialog, then open its nested confirmation. Escape returns focus to the owning trigger.
  • Tab remains within an open modal. Choice popups keep the same theme and reading direction.

States covered

  • Local light and dark scopes
  • Nested modal focus
  • External portal container
  • Live token changes
  • Scoped reduced motion

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-scoped-workspaces-overlays.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,Dialog,DialogClose,Popover,Select,UIProvider,useUIConfig,useReducedMotionPreference} from '@bld8/ui';
function ScopeReadout(){const ui=useUIConfig(),reduced=useReducedMotionPreference();return <p className="bui-hint" data-scope-readout>{ui.locale+' | '+ui.direction+' | '+(reduced?'reduced':'system')}</p>;}
function Review({arabic=false}:{arabic?:boolean}){return <div style={{display:'grid',gap:16,padding:24,background:'var(--bui-surface)',borderRadius:12}}>
  <h3>{arabic?'مساحة المراجعة':'Review workspace'}</h3><ScopeReadout/>
  <Dialog title={arabic?'لوحة المراجعة':'Review panel'} description={arabic?'تخصيص محلي دون تغيير الصفحة.':'Local configuration stays with this workspace.'} trigger={<Button variant="accent">{arabic?'فتح المراجعة':'Open review panel'}</Button>}>
    <div style={{display:'grid',gap:20}}><Select label={arabic?'الحالة':'Review status'} defaultValue="in-review" options={[{value:'in-review',label:arabic?'قيد المراجعة':'In review'},{value:'approved',label:arabic?'معتمد':'Approved'}]}/>
      <Popover title={arabic?'ملاحظات':'Review notes'} trigger={<Button variant="secondary">{arabic?'تفاصيل إضافية':'More review details'}</Button>}><p>{arabic?'الخيارات تحتفظ بنفس الاتجاه والألوان.':'Popup tokens follow this workspace.'}</p></Popover>
      <Dialog title={arabic?'تأكيد المراجعة':'Confirm review'} trigger={<Button>{arabic?'تأكيد':'Open confirmation'}</Button>}><DialogClose>{arabic?'رجوع':'Back to review'}</DialogClose></Dialog>
      <DialogClose/>
    </div>
  </Dialog>
</div>;}
export default function ScopedWorkspaceExample(){
  const external=useRef<HTMLDivElement>(null),[alternate,setAlternate]=useState(false);
  return <div style={{display:'grid',gap:20}}><Button variant="secondary" onClick={()=>setAlternate(value=>!value)}>Change local accent</Button>
    <div style={{display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(min(100%,260px),1fr))',gap:20}}>
      <UIProvider theme="light" locale="en-AU" direction="ltr" tokens={{'--bui-accent':alternate?'#B7E4CD':'#FFD900'}}><div data-scope-workspace="light"><Review/></div></UIProvider>
      <UIProvider theme="dark" locale="ar" direction="rtl" motion="reduced" tokens={{'--bui-accent':'#FFD900'}} portalContainer={external}><div data-scope-workspace="dark"><Review arabic/></div></UIProvider>
    </div><div ref={external} data-external-scope-portals=""/>
  </div>;
}

Quick reference

React / TypeScript
<Dialog trigger={<Button>New project</Button>} title="New project" description="Give the project a name.">
  <Field label="Name"><Input /></Field>
</Dialog>

In the workspace or ZIP starter, import components from @bld8/ui and include @bld8/ui/styles.css once. Registry installations use your local bld8/ source path. Wrap overlays in UIProvider.

API & behaviour

Base UI supplies focus trapping, Escape dismissal and focus restoration. title is required. Supports open/onOpenChange and defaultOpen. trigger accepts a ref-forwarding React element. Use DialogClose within the content.

Dialog

Dialog public properties
PropTypeDefault
childrenRequiredReactNode—
titleRequiredstring—
defaultOpenboolean | undefined—
descriptionstring | undefined—
finalFocusRefObject<HTMLElement | null> | undefined—
initialFocusRefObject<HTMLElement | null> | undefined—
onOpenChange((open: boolean) => void) | undefined—
openboolean | undefined—
triggerReactElement<unknown, string | JSXElementConstructor<any>> | undefined—

DialogClose

DialogClose public properties
PropTypeDefault
childrenReactNode—

Tables come from the public TypeScript declarations. Related types and function parameters are shown alongside their component. A dash means no default is declared at the public function boundary.

Related controls

Notes to self

Test this component with real content, keyboard input and both themes. The example is a starting point; labels, error handling and behaviour still need to fit the application.