|
1 | 1 | mod theme;
|
2 | 2 |
|
3 | 3 | use crate::{
|
4 |
| - components::{Binder, Follower, FollowerPlacement, FollowerWidth}, |
| 4 | + components::{Binder, CSSTransition, Follower, FollowerPlacement, FollowerWidth}, |
5 | 5 | use_theme,
|
6 | 6 | utils::{class_list::class_list, mount_style, Model, OptionalProp, StoredMaybeSignal},
|
7 | 7 | ComponentRef, Input, InputPrefix, InputRef, InputSuffix, Theme,
|
@@ -196,69 +196,76 @@ pub fn AutoComplete(
|
196 | 196 | placement=FollowerPlacement::BottomStart
|
197 | 197 | width=FollowerWidth::Target
|
198 | 198 | >
|
199 |
| - <div |
200 |
| - class="thaw-auto-complete__menu" |
201 |
| - style=move || menu_css_vars.get() |
202 |
| - ref=menu_ref |
| 199 | + <CSSTransition |
| 200 | + node_ref=menu_ref |
| 201 | + name="fade-in-scale-up-transition" |
| 202 | + show=is_show_menu |
| 203 | + let:display |
203 | 204 | >
|
| 205 | + <div |
| 206 | + class="thaw-auto-complete__menu" |
| 207 | + style=move || display.get().map(|d| d.to_string()).unwrap_or_else(|| menu_css_vars.get()) |
| 208 | + ref=menu_ref |
| 209 | + > |
204 | 210 |
|
205 |
| - {move || { |
206 |
| - options |
207 |
| - .get() |
208 |
| - .into_iter() |
209 |
| - .enumerate() |
210 |
| - .map(|(index, v)| { |
211 |
| - let AutoCompleteOption { value: option_value, label } = v; |
212 |
| - let menu_item_ref = create_node_ref::<html::Div>(); |
213 |
| - let on_click = move |_| { |
214 |
| - select_value(option_value.clone()); |
215 |
| - }; |
216 |
| - let on_mouseenter = move |_| { |
217 |
| - select_option_index.set(Some(index)); |
218 |
| - }; |
219 |
| - let on_mousedown = move |ev: ev::MouseEvent| { |
220 |
| - ev.prevent_default(); |
221 |
| - }; |
222 |
| - create_effect(move |_| { |
223 |
| - if Some(index) == select_option_index.get() { |
224 |
| - if !is_show_menu.get() { |
225 |
| - return; |
226 |
| - } |
227 |
| - if let Some(menu_item_ref) = menu_item_ref.get() { |
228 |
| - let menu_ref = menu_ref.get().unwrap(); |
229 |
| - let menu_rect = menu_ref.get_bounding_client_rect(); |
230 |
| - let item_rect = menu_item_ref.get_bounding_client_rect(); |
231 |
| - if item_rect.y() < menu_rect.y() { |
232 |
| - menu_item_ref.scroll_into_view_with_bool(true); |
233 |
| - } else if item_rect.y() + item_rect.height() |
234 |
| - > menu_rect.y() + menu_rect.height() |
235 |
| - { |
236 |
| - menu_item_ref.scroll_into_view_with_bool(false); |
| 211 | + {move || { |
| 212 | + options |
| 213 | + .get() |
| 214 | + .into_iter() |
| 215 | + .enumerate() |
| 216 | + .map(|(index, v)| { |
| 217 | + let AutoCompleteOption { value: option_value, label } = v; |
| 218 | + let menu_item_ref = create_node_ref::<html::Div>(); |
| 219 | + let on_click = move |_| { |
| 220 | + select_value(option_value.clone()); |
| 221 | + }; |
| 222 | + let on_mouseenter = move |_| { |
| 223 | + select_option_index.set(Some(index)); |
| 224 | + }; |
| 225 | + let on_mousedown = move |ev: ev::MouseEvent| { |
| 226 | + ev.prevent_default(); |
| 227 | + }; |
| 228 | + create_effect(move |_| { |
| 229 | + if Some(index) == select_option_index.get() { |
| 230 | + if !is_show_menu.get() { |
| 231 | + return; |
| 232 | + } |
| 233 | + if let Some(menu_item_ref) = menu_item_ref.get() { |
| 234 | + let menu_ref = menu_ref.get().unwrap(); |
| 235 | + let menu_rect = menu_ref.get_bounding_client_rect(); |
| 236 | + let item_rect = menu_item_ref.get_bounding_client_rect(); |
| 237 | + if item_rect.y() < menu_rect.y() { |
| 238 | + menu_item_ref.scroll_into_view_with_bool(true); |
| 239 | + } else if item_rect.y() + item_rect.height() |
| 240 | + > menu_rect.y() + menu_rect.height() |
| 241 | + { |
| 242 | + menu_item_ref.scroll_into_view_with_bool(false); |
| 243 | + } |
237 | 244 | }
|
238 | 245 | }
|
239 |
| - } |
240 |
| - }); |
241 |
| - view! { |
242 |
| - <div |
243 |
| - class="thaw-auto-complete__menu-item" |
244 |
| - class=( |
245 |
| - "thaw-auto-complete__menu-item--selected", |
246 |
| - move || Some(index) == select_option_index.get(), |
247 |
| - ) |
| 246 | + }); |
| 247 | + view! { |
| 248 | + <div |
| 249 | + class="thaw-auto-complete__menu-item" |
| 250 | + class=( |
| 251 | + "thaw-auto-complete__menu-item--selected", |
| 252 | + move || Some(index) == select_option_index.get(), |
| 253 | + ) |
248 | 254 |
|
249 |
| - on:click=on_click |
250 |
| - on:mousedown=on_mousedown |
251 |
| - on:mouseenter=on_mouseenter |
252 |
| - ref=menu_item_ref |
253 |
| - > |
254 |
| - {label} |
255 |
| - </div> |
256 |
| - } |
257 |
| - }) |
258 |
| - .collect_view() |
259 |
| - }} |
| 255 | + on:click=on_click |
| 256 | + on:mousedown=on_mousedown |
| 257 | + on:mouseenter=on_mouseenter |
| 258 | + ref=menu_item_ref |
| 259 | + > |
| 260 | + {label} |
| 261 | + </div> |
| 262 | + } |
| 263 | + }) |
| 264 | + .collect_view() |
| 265 | + }} |
260 | 266 |
|
261 |
| - </div> |
| 267 | + </div> |
| 268 | + </CSSTransition> |
262 | 269 | </Follower>
|
263 | 270 | </Binder>
|
264 | 271 | }
|
|
0 commit comments