mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
feat: RadioGroup adds name prop
This commit is contained in:
parent
9e6a1220d5
commit
61b937f688
2 changed files with 13 additions and 4 deletions
|
@ -23,14 +23,14 @@ pub fn Radio(
|
|||
move |_| {
|
||||
item_value.with_value(|value| {
|
||||
group
|
||||
.0
|
||||
.value
|
||||
.with(|group_value| group_value.as_ref() == Some(value))
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
let on_change = move |_| {
|
||||
group.0.set(Some(item_value.get_value()));
|
||||
group.value.set(Some(item_value.get_value()));
|
||||
};
|
||||
|
||||
view! {
|
||||
|
@ -43,6 +43,7 @@ pub fn Radio(
|
|||
class="thaw-radio__input"
|
||||
type="radio"
|
||||
id=id.clone()
|
||||
name=group.name
|
||||
value=item_value.get_value()
|
||||
prop:checked=move || checked.get()
|
||||
on:change=on_change
|
||||
|
|
|
@ -4,10 +4,15 @@ use thaw_utils::Model;
|
|||
#[component]
|
||||
pub fn RadioGroup(
|
||||
#[prop(optional, into)] value: Model<Option<String>>,
|
||||
/// The name of this radio group.
|
||||
#[prop(optional, into)]
|
||||
name: Option<String>,
|
||||
children: Children,
|
||||
) -> impl IntoView {
|
||||
let name = name.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
|
||||
|
||||
view! {
|
||||
<Provider value=RadioGroupInjection(value)>
|
||||
<Provider value=RadioGroupInjection{ value, name }>
|
||||
<div class="thaw-radio-group" role="radiogroup" style="display: flex;align-items: flex-start">
|
||||
{children()}
|
||||
</div>
|
||||
|
@ -16,7 +21,10 @@ pub fn RadioGroup(
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RadioGroupInjection(pub Model<Option<String>>);
|
||||
pub(crate) struct RadioGroupInjection {
|
||||
pub value: Model<Option<String>>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl RadioGroupInjection {
|
||||
pub fn use_() -> RadioGroupInjection {
|
||||
|
|
Loading…
Add table
Reference in a new issue