Skip to main content

Modal

A dialog component that appears in front of the main content to provide critical information or ask for user input.

Usage

import { Modal } from '@blendx-ui';

// Basic usage
function ModalExample() {
const [show, setShow] = useState(false);

return (
<>
<Button onClick={() => setShow(true)}>Open Modal</Button>

<Modal
show={show}
onHide={() => setShow(false)}
title="Modal Title"
>
<Modal.Header closeButton>
<Modal.Title>Modal Title</Modal.Title>
</Modal.Header>
<Modal.Body>
Modal content goes here...
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShow(false)}>
Close
</Button>
<Button variant="primary" onClick={handleSave}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
</>
);
}

Props

PropTypeRequiredDefaultDescription
showbooleanYes-Whether the modal is visible
onHidefunctionYes-Callback when modal is hidden
titlestringNo-Title for the modal (alternative to using Modal.Title)
sizestringNo'md'Size of the modal ('sm', 'md', 'lg', 'xl')
centeredbooleanNofalseWhether to center the modal vertically
backdropboolean or 'static'NotrueWhether to show backdrop ('static' prevents closing on backdrop click)
animationbooleanNotrueWhether to animate when showing/hiding
scrollablebooleanNofalseWhether the modal body can scroll
dialogClassNamestringNo-Custom class for the modal dialog
contentClassNamestringNo-Custom class for the modal content
backdropClassNamestringNo-Custom class for the modal backdrop
keyboardbooleanNotrueWhether pressing escape closes the modal
fullscreenboolean or stringNofalseWhether modal takes up the full screen ('sm-down', 'md-down', etc. for responsive)
enforceFocusbooleanNotrueWhether to enforce focus in the modal
restoreFocusbooleanNotrueWhether to restore focus after closing
autoFocusbooleanNotrueWhether to auto-focus when modal opens
childrennodeNo-Modal content

Parameters

onHide

  • Parameters: () - No parameters
  • Returns: void

onShow

  • Parameters: () - No parameters
  • Returns: void

onEntered

  • Parameters: () - No parameters
  • Returns: void

onExit

  • Parameters: () - No parameters
  • Returns: void

Return Value

Returns a modal component with the following subcomponents:

  • Modal.Header - Contains the modal header content
  • Modal.Title - Modal title that can be used inside Header
  • Modal.Body - Contains the main modal content
  • Modal.Footer - Contains the modal footer (typically action buttons)
  • Modal.Dialog - The modal dialog wrapper (rarely used directly)

Examples

Basic Modal

const [show, setShow] = useState(false);

<>
<Button onClick={() => setShow(true)}>Open Modal</Button>

<Modal show={show} onHide={() => setShow(false)}>
<Modal.Header closeButton>
<Modal.Title>Modal Title</Modal.Title>
</Modal.Header>
<Modal.Body>This is the modal content.</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShow(false)}>
Close
</Button>
<Button variant="primary" onClick={handleSave}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
</>

Static Backdrop Modal

<Modal
show={show}
onHide={handleClose}
backdrop="static"
keyboard={false}
>
<Modal.Header closeButton>
<Modal.Title>Cannot Close By Backdrop</Modal.Title>
</Modal.Header>
<Modal.Body>
You can only close this by clicking the Close button.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
</Modal.Footer>
</Modal>

Centered Modal

<Modal
show={show}
onHide={handleClose}
centered
>
<Modal.Header closeButton>
<Modal.Title>Centered Modal</Modal.Title>
</Modal.Header>
<Modal.Body>This modal is vertically centered.</Modal.Body>
<Modal.Footer>
<Button onClick={handleClose}>Close</Button>
</Modal.Footer>
</Modal>

Scrollable Modal

<Modal
show={show}
onHide={handleClose}
scrollable
>
<Modal.Header closeButton>
<Modal.Title>Scrollable Modal</Modal.Title>
</Modal.Header>
<Modal.Body>
{/* Long content that will make the modal scroll */}
<p>...</p>
</Modal.Body>
<Modal.Footer>
<Button onClick={handleClose}>Close</Button>
</Modal.Footer>
</Modal>

Fullscreen Modal

<Modal
show={show}
onHide={handleClose}
fullscreen
>
<Modal.Header closeButton>
<Modal.Title>Fullscreen Modal</Modal.Title>
</Modal.Header>
<Modal.Body>This modal takes up the entire screen.</Modal.Body>
<Modal.Footer>
<Button onClick={handleClose}>Close</Button>
</Modal.Footer>
</Modal>

Accessibility

  • Sets proper ARIA attributes for dialog role
  • Manages focus properly to ensure keyboard accessibility
  • Supports keyboard navigation (Escape key closes the modal)
  • Returns focus to the element that triggered the modal when closed
  • Traps focus within the modal for better accessibility

Best Practices

  • Always include a close button or method to dismiss the modal
  • Keep modal content concise and focused on a single task
  • Use appropriate modal sizes for the content
  • For destructive actions, include confirmation or cancel options
  • Consider using static backdrop for critical forms to prevent accidental dismissal
  • Ensure all interactive elements within the modal are accessible
  • ModalDialog
  • FullscreenModal
  • StandardModal
  • AlertModal
  • MarketingModal
  • Drawer
  • Popover

Notes

  • Based on React Bootstrap's Modal component
  • For more complex modal patterns, consider the specialized modal components like AlertModal or FullscreenModal

Dependencies

RepositoryUsage Count
frontend-app-staff-dashboard10
frontend-app-dashboard3
frontend-app-course-authoring1
frontend-app-account2

Detailed usage locations:

frontend-app-staff-dashboard

  • src/components/DocumentCard.jsx
  • src/components/GetContactModal.jsx
  • src/components/Support.jsx
  • src/components/VideoCard.jsx
  • src/pages/calendar/index.jsx
  • src/pages/program-single/enrollment/EnrollDrawer.jsx
  • src/pages/program-single/settings/DeleteProgramModal.jsx
  • src/pages/users/index.jsx
  • src/pages/users/teams/TeamSingle.jsx
  • src/pages/users/teams/index.jsx

frontend-app-dashboard

  • src/components/GetContactModal.jsx
  • src/pages/calendar/index.jsx
  • src/pages/support/actionModalSupport.jsx

frontend-app-course-authoring

  • src/enrollments/EnrollDrawer.jsx

frontend-app-account

  • src/account-settings/delete-account/ConfirmationModal.jsx
  • src/account-settings/delete-account/SuccessModal.jsx