Skip to content

How to add children to a Custom component? #722

Answered by gbj
tversteeg asked this question in Q&A
Discussion options

You must be logged in to vote

Oh yeah totally possible. The syntax in the builder to add a child or children to any element is .child(). So for example you could do

#[component]
fn MdDialog(cx: Scope, children: Children) -> impl IntoView {
    custom(cx, Custom::new("md-outlined-text-field"))
        .child(children(cx))
}

or, if you want to add each child separately without the fragment, something like

#[component]
fn MdDialog(cx: Scope, children: Children) -> impl IntoView {
    let children = children(cx);
    let el = custom(cx, Custom::new("md-outlined-text-field"));
    children
        .nodes
        .into_iter()
        .fold(el, |el, child| el.child(child))
}

BTW Are you working on a Material Design wrapper l…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tversteeg
Comment options

@gbj
Comment options

gbj Mar 22, 2023
Maintainer

@tversteeg
Comment options

@gbj
Comment options

gbj Mar 23, 2023
Maintainer

Answer selected by tversteeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants