singlestage/components/select/
item.rs1use super::SelectContext;
2use crate::Reactive;
3use leptos::prelude::*;
4
5#[component]
6pub fn SelectItem(
7 children: Children,
8
9 #[prop(optional, into)]
14 accesskey: MaybeProp<String>,
15 #[prop(optional, into)]
20 autocapitalize: MaybeProp<String>,
21 #[prop(optional, into)]
24 autofocus: MaybeProp<bool>,
25 #[prop(optional, into)]
27 class: MaybeProp<String>,
28 #[prop(optional, into)]
32 contenteditable: MaybeProp<String>,
33 #[prop(optional, into)]
37 dir: MaybeProp<String>,
38 #[prop(optional, into)]
40 draggable: MaybeProp<bool>,
41 #[prop(optional, into)]
43 enterkeyhint: MaybeProp<String>,
44 #[prop(optional, into)]
46 exportparts: MaybeProp<String>,
47 #[prop(optional, into)]
49 hidden: MaybeProp<String>,
50 #[prop(optional, into)]
52 id: MaybeProp<String>,
53 #[prop(optional, into)]
55 inert: MaybeProp<bool>,
56 #[prop(optional, into)]
59 inputmode: MaybeProp<String>,
60 #[prop(optional, into)]
62 is: MaybeProp<String>,
63 #[prop(optional, into)]
65 itemid: MaybeProp<String>,
66 #[prop(optional, into)]
68 itemprop: MaybeProp<String>,
69 #[prop(optional, into)]
71 itemref: MaybeProp<String>,
72 #[prop(optional, into)]
74 itemscope: MaybeProp<String>,
75 #[prop(optional, into)]
77 itemtype: MaybeProp<String>,
78 #[prop(optional, into)]
80 lang: MaybeProp<String>,
81 #[prop(optional, into)]
83 nonce: MaybeProp<String>,
84 #[prop(optional, into)]
86 part: MaybeProp<String>,
87 #[prop(optional, into)]
89 popover: MaybeProp<String>,
90 #[prop(optional, into)]
92 role: MaybeProp<String>,
93 #[prop(optional, into)]
95 slot: MaybeProp<String>,
96 #[prop(optional, into)]
100 spellcheck: MaybeProp<String>,
101 #[prop(optional, into)]
103 style: MaybeProp<String>,
104 #[prop(optional, into)]
106 tabindex: MaybeProp<usize>,
107 #[prop(optional, into)]
109 title: MaybeProp<String>,
110 #[prop(optional, into)]
112 translate: MaybeProp<String>,
113
114 #[prop(optional, into)]
116 disabled: MaybeProp<bool>,
117 #[prop(optional, into)]
119 label: MaybeProp<String>,
120 #[prop(optional, into)]
122 selected: Reactive<bool>,
123 #[prop(optional, into)]
125 value: MaybeProp<String>,
126) -> impl IntoView {
127 let select_context = expect_context::<SelectContext>();
128
129 if let Some(value) = value.get_untracked() {
130 selected.set(value == select_context.value.get_untracked())
131 };
132
133 Effect::new(move || {
134 if let Some(value) = value.get() {
135 selected.set(value == select_context.value.get())
136 }
137 });
138
139 let global_attrs_1 = view! {
140 <{..}
141 accesskey=move || accesskey.get()
142 autocapitalize=move || autocapitalize.get()
143 autofocus=move || autofocus.get()
144 class=move || class.get()
145 contenteditable=move || contenteditable.get()
146 dir=move || dir.get()
147 draggable=move || draggable.get()
148 enterkeyhint=move || enterkeyhint.get()
149 exportparts=move || exportparts.get()
150 hidden=move || hidden.get()
151 id=move || id.get()
152 inert=move || inert.get()
153 inputmode=move || inputmode.get()
154 is=move || is.get()
155 itemid=move || itemid.get()
156 />
157 };
158
159 let global_attrs_2 = view! {
160 <{..}
161 itemprop=move || itemprop.get()
162 itemref=move || itemref.get()
163 itemscope=move || itemscope.get()
164 itemtype=move || itemtype.get()
165 lang=move || lang.get()
166 nonce=move || nonce.get()
167 part=move || part.get()
168 popover=move || popover.get()
169 role=move || role.get()
170 slot=move || slot.get()
171 spellcheck=move || spellcheck.get()
172 style=move || style.get()
173 tabindex=move || tabindex.get()
174 title=move || title.get()
175 translate=move || translate.get()
176 />
177 };
178
179 view! {
180 <option
181 disabled=move || disabled.get()
182 label=move || label.get()
183 selected=move || selected.get()
184 value=move || value.get()
185
186 {..global_attrs_1}
187 {..global_attrs_2}
188 >
189 {children()}
190 </option>
191 }
192}