Button
Clickable button with variants (default, destructive, outline, secondary, ghost, link) and sizes.
Installation
Add the Button component using the CLI:
Usage
Basic button with text content. Use ChildContent to render anything inside—text, markup, or components.
Examples
Size
Use the Size parameter for compact (Sm), default (Md), or larger (Lg) buttons. Sizing affects padding and text scale.
Variants
Choose a Variant to convey hierarchy: Default for primary actions, Outline for secondary, Ghost for minimal emphasis, Destructive for dangerous actions, and Link for inline-style buttons.
Content
The button accepts any content via ChildContent. Mix text with inline elements, or use dynamic content. The component handles layout and spacing automatically.
Icons
Use Lucide icons (or any SVG) inside the button. Add the icon package and place it alongside text—spacing is handled by the button's built-in gap. Icon-only buttons work with smaller sizes and padding.
Icon-only and accessibility
For icon-only buttons, screen readers need an accessible name. Pass aria-label via AdditionalAttributes—we keep it attribute-only to avoid parameter bloat and stay consistent with HTML.
Spinner
Use State="ButtonState.Loading" for async actions. The button is disabled and gets aria-busy="true" so screen readers announce that it's processing. Render a spinner inside for visual feedback.
Disabled
Use State="ButtonState.Disabled" when the action is unavailable. Unlike Loading, this sets aria-disabled="true" (not aria-busy)—screen readers announce "disabled" rather than "busy", so users understand the control is inactive, not processing.
Interactivity
Wire up OnClick to handle user actions. The handler receives MouseEventArgs. Use component state to drive dynamic labels or behavior.
Button Group
Use ButtonGroup to group related buttons with shared borders and styling. Set Variant for Default, Outline, Ghost, or other styles. Use Role="toolbar" for toolbar groups. Buttons inside the group share the group's visual style.
API Reference
Button
A clickable button with configurable variant, size, and type.
Properties
| Name | Type | Description |
|---|---|---|
Size |
Size |
The size of the button. |
Variant |
Variant |
The visual style variant of the button. |
OnClick |
EventCallback<MouseEventArgs> |
Callback fired when the button is clicked. |
State |
Nullable<ButtonState> |
The button state. When Loading, the button is disabled with aria-busy. When Disabled, the button is disabled. When null, normal. |
Type |
ButtonType |
The HTML button type (button, submit, or reset). |
AdditionalAttributes |
Dictionary<string, Object> |
|
Class |
string |
|
ChildContent |
RenderFragment |
The content rendered inside the button. |
Events
| Name | Type | Description |
|---|---|---|
OnClick |
EventCallback<MouseEventArgs> |
Callback fired when the button is clicked. |
Methods
| Method | Returns | Description |
|---|---|---|
Equals |
bool |
|
GetHashCode |
int |
|
GetType |
Type |
|
SetParametersAsync |
Task |
|
ToString |
string |