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

[0.7] MaybeProp can't be passed as attribute #3240

Open
DanielleHuisman opened this issue Nov 13, 2024 · 1 comment
Open

[0.7] MaybeProp can't be passed as attribute #3240

DanielleHuisman opened this issue Nov 13, 2024 · 1 comment

Comments

@DanielleHuisman
Copy link
Contributor

Describe the bug

Passing a MaybeProp as attribute gives an error:

#[component]
fn TestButton(#[prop(into, optional)] id: MaybeProp<String>, children: Children) -> impl IntoView {
    view! {
        <button id=id>
            {children()}
        </button>
    }
}
error[E0277]: the trait bound `leptos::prelude::MaybeProp<std::string::String>: leptos::prelude::IntoAttributeValue` is not satisfied
   --> packages/leptos/button/src/default.rs:115:20
    |
114 | /     view! {
115 | |         <button id=id>
    | |                    ^^ the trait `FnMut()` is not implemented for `leptos::prelude::MaybeProp<std::string::String>`, which is required by `leptos::prelude::MaybeProp<std::string::String>: leptos::prelude::IntoAttributeValue`
116 | |             {children()}
117 | |         </button>
118 | |     }
    | |_____- required by a bound introduced by this call
    |
    = note: required for `leptos::prelude::MaybeProp<std::string::String>` to implement `leptos::tachys::reactive_graph::ReactiveFunction`
    = note: required for `leptos::prelude::MaybeProp<std::string::String>` to implement `leptos::attr::AttributeValue`
    = note: required for `leptos::prelude::MaybeProp<std::string::String>` to implement `leptos::prelude::IntoAttributeValue`

However, manually calling .get() works fine:

#[component]
fn TestButton(#[prop(into, optional)] id: MaybeProp<String>, children: Children) -> impl IntoView {
    view! {
        <button id=move || id.get()>
            {children()}
        </button>
    }
}

Leptos Dependencies

Please copy and paste the Leptos dependencies and features from your Cargo.toml.

# Latest commit on main branch
leptos = { git = "https://github.com/leptos-rs/leptos.git", rev = "c2b239d" }

Expected behavior

I would expect MaybeProp to be accepted as is, without manually calling .get().

@gbj
Copy link
Collaborator

gbj commented Nov 13, 2024

PR welcome to add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants