React Bootstrap Close Button
The React Bootstrap close button of AdminKit: a .btn-close button with an accessible label, used by alerts, modals, offcanvas sheets and toasts.
Every dialog, side panel and dismissible message needs a way out. CloseButton is that small X button: Bootstrap's .btn-close as a React component, with type="button" and aria-label="Close" already set. It is in the free and PRO versions of AdminKit for React.
A dismissible alert adds one itself. In a modal or an offcanvas header, you add it yourself, with an onClick that closes the dialog.
Example
import { CloseButton } from "@/components/bootstrap/close-button";
export function CloseButtons({ onClose }: { onClose: () => void }) {
return (
<>
<CloseButton onClick={onClose} />
<CloseButton disabled />
</>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
white | boolean | Adds .btn-close-white, a light icon for dark backgrounds |
Other props, such as onClick, disabled, className and aria-label, go to the <button>. A disabled close button is faded and ignores clicks. The component is in src/components/bootstrap/close-button.tsx.
On a dark background
On a dark surface, the default icon is hard to see. white turns the icon light. The toasts of AdminKit PRO use it when their text is light.
<div className="bg-dark p-3 rounded">
<CloseButton white onClick={close} />
</div>Accessibility
- The button has no visible text, so
aria-label="Close"names it. Pass a more specific label when several close buttons are near each other, such asaria-label="Close filters". - It is a real
<button>: it takes the focus, and Enter and Space activate it.
Related
- Next.js Bootstrap close button: the same component in AdminKit for Next.js
- Bootstrap 5 close button: the close button of the HTML version
- Modal: a dialog with a close button in its header
- Alerts demo: dismissible alerts with a close button
Last updated on
Card
React Bootstrap card markup as AdminKit uses it: header with title, body, footer, images, list groups, clickable cards and cards rendered from an array.
CollapsePro
A React Bootstrap collapse component: show and hide content from a boolean in React state, with Bootstrap's animated height transition and transition callbacks.