Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node_ref and id to Button component #43

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/yew-bootstrap/src/component/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ pub struct ButtonProps {
/// the button is not `disabled`.
#[prop_or_default]
pub target: Option<AttrValue>,

/// Reference to the [NodeRef] of the button's underlying `<button>` or
/// `<a>` element.
///
/// Used by components which add custom event handlers directly to the DOM.
///
/// See [*Node Refs* in the Yew documentation][0] for more information.
///
/// [0]: https://yew.rs/docs/concepts/function-components/node-refs
#[prop_or_default]
pub node_ref: NodeRef,

/// Optional HTML element ID for the underlying `<button>` or `<a>` element.
#[prop_or_default]
pub id: Option<AttrValue>,
}

impl Component for Button {
Expand Down Expand Up @@ -182,6 +197,8 @@ impl Component for Button {
onclick={props.onclick.clone()}
data-bs-toggle="modal"
data-bs-target={format!("#{}",target.clone())}
ref={props.node_ref.clone()}
id={props.id.clone()}
>
{ &props.text }
{ for props.children.iter() }
Expand All @@ -197,6 +214,8 @@ impl Component for Button {
data-bs-dismiss={modal_dismiss}
href={url.clone()}
target={props.target.clone()}
ref={props.node_ref.clone()}
id={props.id.clone()}
>
{ &props.text }
{ for props.children.iter() }
Expand All @@ -210,6 +229,8 @@ impl Component for Button {
name={props.name.clone()}
onclick={props.onclick.clone()}
data-bs-dismiss={modal_dismiss}
ref={props.node_ref.clone()}
id={props.id.clone()}
>
{ &props.text }
{ for props.children.iter() }
Expand Down
Loading