pub struct ButtonProps {Show 17 fields
pub color: Color,
pub outline: bool,
pub link: bool,
pub plain: bool,
pub size: Size,
pub disabled: bool,
pub href: Option<String>,
pub target: Option<String>,
pub rel: Option<String>,
pub role: Option<String>,
pub download: Option<String>,
pub type: String,
pub onclick: Option<EventHandler<MouseEvent>>,
pub onmousedown: Option<EventHandler<MouseEvent>>,
pub active: bool,
pub class: String,
pub children: Element,
/* private fields */
}Expand description
Bootstrap Button component.
Renders a <button> by default. When href is set, renders an <a> element
instead (Bootstrap link-button pattern).
Accepts all standard HTML attributes via extends = GlobalAttributes.
This means title, data-bs-toggle, aria-label, id, etc. all work.
§Bootstrap HTML → Dioxus
| HTML | Dioxus |
|---|---|
<button class="btn btn-primary"> | Button { color: Color::Primary, "Text" } |
<button class="btn btn-outline-danger btn-sm"> | Button { color: Color::Danger, outline: true, size: Size::Sm, "Text" } |
<button class="btn btn-link btn-sm"> | Button { link: true, size: Size::Sm, "Text" } |
<button class="btn btn-sm"> (neutral, no color variant) | Button { plain: true, size: Size::Sm, "Text" } |
<button class="btn btn-success btn-lg" disabled> | Button { color: Color::Success, size: Size::Lg, disabled: true, "Text" } |
<a class="btn btn-primary" href="/page"> | Button { color: Color::Primary, href: "/page", "Link" } |
<a class="btn btn-sm" href="f.json" target="_blank" download="f.json"> | Button { size: Size::Sm, href: "f.json", target: "_blank", download: "f.json", "DL" } |
<button class="btn btn-primary" title="Tip"> | Button { color: Color::Primary, title: "Tip", "Text" } |
rsx! {
Button { color: Color::Primary, "Click me" }
Button { color: Color::Danger, outline: true, size: Size::Sm, "Delete" }
Button { color: Color::Success, disabled: true, "Saved" }
Button { color: Color::Warning, onclick: move |_| { /* handler */ }, "Action" }
// Link button — renders <a> instead of <button>:
Button { color: Color::Primary, href: "/page", "Go to Page" }
// HTML attributes work directly:
Button { color: Color::Secondary, title: "Tooltip text", "Hover me" }
Button { color: Color::Primary, "data-bs-toggle": "modal", "Open Modal" }
}Fields§
§color: ColorButton color variant.
outline: boolUse outline style instead of filled.
link: boolUse Bootstrap link-button style (btn-link).
plain: boolRender a neutral button with no color variant: bare .btn (Bootstrap’s
base button already renders neutral — body-colored text, transparent
background and border, with the standard focus ring and pointer cursor).
Pair with utility classes (border-0, p-0, …) for ghost / borderless /
text-button styles. Takes precedence over outline; ignored when link
is set.
size: SizeButton size.
disabled: boolWhether the button is disabled.
href: Option<String>When set, renders an <a> element instead of <button> (link-button pattern).
target: Option<String>Link target (e.g., "_blank"). Only used when href is set.
rel: Option<String>Link relationship (e.g., "noopener noreferrer"). Only used when href
is set — and the pairing that makes target: "_blank" safe, so the two
belong together.
role: Option<String>ARIA role. Overrides the role="button" a link-button renders by
default; unset on a real <button>, which needs none.
This has to be a prop rather than something the caller passes through
attributes: the spread is appended, not merged, so a role supplied
that way emits role="button" role="link" — and HTML keeps the first
duplicate, so the override is silently discarded while looking exactly
like it worked.
download: Option<String>Download filename. Only used when href is set.
type: StringHTML button type attribute (ignored when href is set).
onclick: Option<EventHandler<MouseEvent>>Click event handler.
onmousedown: Option<EventHandler<MouseEvent>>Mouse-down handler. A toolbar button needs it to prevent_default and
keep the caret in the field it acts on. GlobalAttributes carries
attributes, not listeners, so this cannot ride along in attributes.
active: boolActive (pressed) state.
class: StringAdditional CSS classes.
children: ElementChild elements.
Implementations§
Source§impl ButtonProps
impl ButtonProps
Sourcepub fn builder() -> ButtonPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
pub fn builder() -> ButtonPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
Create a builder for building ButtonProps.
On the builder, call .color(...)(optional), .outline(...)(optional), .link(...)(optional), .plain(...)(optional), .size(...)(optional), .disabled(...)(optional), .href(...)(optional), .target(...)(optional), .rel(...)(optional), .role(...)(optional), .download(...)(optional), .r#type(...)(optional), .onclick(...)(optional), .onmousedown(...)(optional), .active(...)(optional), .class(...)(optional), .attributes(...)(optional), .children(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of ButtonProps.
Trait Implementations§
Source§impl Clone for ButtonProps
impl Clone for ButtonProps
Source§fn clone(&self) -> ButtonProps
fn clone(&self) -> ButtonProps
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more