Modal Component
Modal Examples with useModal Hook
Simple Modal
Responsive Fullscreen (Breakpoint)
Toggle Modal (with State Tracking)
Alert Modals (Single Button)
Confirmation Modals (Two Buttons)
Fullscreen Modal
Responsive & Placement
Custom Width
Behavior Options
Custom Footer
Form in Modal
useModal Hook Usage
const { modalRef, open, close, toggle, isOpen } = useModal() ;// With callbacksconst { modalRef, open } = useModal({ onOpen: () => console.log('Opened'), onClose: () => console.log('Closed'),}) ;<Button onClick={ open }>Open</Button><Modal ref={ modalRef }>Content</Modal>Stacked Modals (Nesting)
You can open multiple modals on top of each other. The browser handles the stacking order.
Toast over Modal
Click to verify that toasts appear above the modal backdrop. Test case: native <dialog> top layer vs ToastProvider popover.
These buttons fire a toast first, then open a modal a few hundred milliseconds later. Without the MutationObserver in the provider, the modal would steal the top of the top-layer stack and hide the toast. With it, the toast popover is re-promoted as soon as the new <dialog> opens.
Try every combination (3 × 3 = 9 positions): top / middle / bottom × start / center / end. Each toast should anchor at the chosen corner, edge or center — independently of where the modal sits.
CRUD Hooks Demo
useAddModal, useEditModal, useRemoveModal
| Name | Phone | Role | Actions | |
|---|---|---|---|---|
AJ Alice Johnson | alice@example.com | 555-0101 | Developer | |
BS Bob Smith | bob@example.com | 555-0102 | Designer | |
CB Charlie Brown | charlie@example.com | 555-0103 | Manager | |
DP Diana Prince | diana@example.com | 555-0104 | Developer |
useAddModal State
useEditModal State
useRemoveModal State
InputModal - Open on Focus Demo
Click on the input or use the button to open the modal
With openOnFocus
Click the input field or the button to open
#3b82f6
Without openOnFocus
Only the button opens the modal
When to use openOnFocus?
✅ Good for:
- Date pickers
- Time pickers
- Color pickers
- Single-click selections
- Read-only inputs
❌ Avoid for:
- Complex forms
- Multi-step selections
- When typing is needed
- File uploads
- Editable inputs
// ✅ Pattern correct avec état temporaireconst [value, setValue] = useState(initial) ;const [tempValue, setTempValue] = useState(initial) ;<InputModal value={value} // Affiche finale onModalOpen={() => setTempValue(value)} onAgree={() => setValue(tempValue)}> <input value={tempValue} onChange={setTempValue} /></InputModal>Additional Options
Hide Action Button
Use showActionButton={false} to hide the button
Custom onFocus Handler
Combine with your own focus handler