Skip to content

Commit

Permalink
Merge pull request #43 from micolous/button-node-ref
Browse files Browse the repository at this point in the history
Add node_ref and id to Button component
  • Loading branch information
isosphere authored Sep 2, 2024
2 parents b8c3b80 + 60b8c77 commit 7c5447a
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 7c5447a

Please sign in to comment.