Oihana Next UI - 0.1.11

Application logo

Modal Component

Modal Examples with useModal Hook

Simple Modal

Responsive Fullscreen (Breakpoint)

Toggle Modal (with State Tracking)

Closed

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 callbacks
const { 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.

CRUD Hooks Demo

useAddModal, useEditModal, useRemoveModal

Total Users
4
Developers
2
Designers
1
NameEmailPhoneRoleActions
AJ
Alice Johnson
alice@example.com555-0101Developer
BS
Bob Smith
bob@example.com555-0102Designer
CB
Charlie Brown
charlie@example.com555-0103Manager
DP
Diana Prince
diana@example.com555-0104Developer

useAddModal State

valid:

useEditModal State

hasChanges:
valid:

useRemoveModal State

ready: ✓

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

Try clicking the input field - nothing happens. You must use the "Choose" button.

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 temporaire
const [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