CloseButton
An icon-only dismiss control with a built-in glyph and label
Usage
Renders an icon-only dismiss button: the X glyph and the accessible name Close are built in.
import {CloseButton} from "@peakui/react";Examples
With a Custom Icon
Children replace the default glyph; the name still comes from aria-label.
Interactive
onPress fires on click and on Enter and Space alike.
Disabled State
Customization
Tailwind CSS
Pass utilities through className. They are merged with the button's own classes.
<CloseButton className="rounded-full" />Global CSS
Override the button's classes in the components layer.
@layer components {
.close-button--default {
@apply bg-danger-soft text-danger-soft-foreground;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The CloseButton component uses these CSS classes (view source styles):
Base Classes
.close-button- Base styles: a 24px square icon-only button
Variant Classes
.close-button--default- Default fill:bg-defaultbackground with a muted glyph
Slots
[data-slot="close-button"]- The button element[data-slot="close-button-icon"]- The default X glyph, ansvg
Interactive States
The button supports both CSS pseudo-classes and data attributes:
- Hover:
:hoveror[data-hovered] - Pressed:
:activeor[data-pressed] - Focus:
:focus-visibleor[data-focus-visible](shows the focus ring) - Disabled:
:disabled,[data-disabled]or[aria-disabled="true"] - Pending:
[data-pending="true"]
API Reference
CloseButton
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'default' | Visual variant |
children | ReactNode | (values: ButtonRenderProps) => ReactNode | built-in X glyph | Button content, or a function of the button's state |
className | string | (values: ButtonRenderProps) => string | - | Additional classes, or a function of the button's state |
aria-label defaults to Close and a consumer value overrides it. type defaults to button. Every other React Aria Button prop is accepted.
Render Props
When children or className is a function, it receives:
| Prop | Type | Description |
|---|---|---|
isPending | boolean | Whether the button is waiting on an action |
isPressed | boolean | Whether the button is currently pressed |
isHovered | boolean | Whether the button is hovered |
isFocused | boolean | Whether the button is focused |
isFocusVisible | boolean | Whether the button is focused by keyboard |
isDisabled | boolean | Whether the button is disabled |