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 prop(attrs) extra attributes to relevant top level elements of components #63

Closed
Panaetius opened this issue Dec 31, 2023 · 3 comments

Comments

@Panaetius
Copy link

Panaetius commented Dec 31, 2023

I really like the DatePicker, but I want to add a label for it with the <label for="id"> tag. For this the input of the datepicker would need to have a corresponding id and there's currently no way to add that.

Leptos supports passing in dynamic attributes like

#[component]
pub fn DatePicker(
    #[prop(optional, into)] value: RwSignal<Option<NaiveDate>>,
    #[prop(optional, into)] class: MaybeSignal<String>,
+    #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
) -> impl IntoView {
    [...]
-    <Input class value=show_date_text on_focus=open_panel on_blur=on_input_blur>
+    <Input class value=show_date_text on_focus=open_panel on_blur=on_input_blur {..attrs}>
    [...]

which can then be used like

<DatePicker value=... attr:id=my-id />

i.e. it allows to pass in arbitrary settings to a component. Of course with some components it's not clear which HTML tag should get the attributes, but for the DatePicker I think the input field makes sense. It also allows setting other things like alt text, maxLength etc. That should be much easier than adding manual support for all the various properties.

In general it'd be nice to add this on all components (not just DatePicker) where it makes sense, it'd make them much more reusable.

@luoxiaozero
Copy link
Collaborator

Looking good, we can start by adding the Input component and its associated components.

@luoxiaozero
Copy link
Collaborator

luoxiaozero commented Jan 2, 2024

Added, please see #65 for details.

@Panaetius
Copy link
Author

awesome, thank you so much! just tested it and can confirm it works

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

No branches or pull requests

2 participants