euv-ui 0.37.4

Reusable UI component library for the euv framework, providing buttons, cards, modals, inputs, and more.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
use super::*;

/// Returns whether a suggestion matches the typed text.
///
/// The comparison is case-insensitive and looks at both the label and the
/// value of the suggestion, so `rust` matches the label "Rust" and the
/// value `rust-lang` alike. An empty query matches every suggestion.
///
/// # Arguments
///
/// - `&EuvAutoCompleteOption` - The suggestion under test.
/// - `&str` - The typed text.
///
/// # Returns
///
/// - `bool` - `true` when the suggestion belongs in the filtered list.
pub fn auto_complete_matches(option: &EuvAutoCompleteOption, query: &str) -> bool {
    matches_lowered(option, &query.to_lowercase())
}

/// Returns whether a suggestion matches an already lower-cased query.
///
/// The component lower-cases the typed text once per render and hands the
/// result to this helper, so the filter does not allocate a copy of the
/// query for every suggestion it walks.
///
/// # Arguments
///
/// - `&EuvAutoCompleteOption` - The suggestion under test.
/// - `&str` - The typed text, already lower-cased.
///
/// # Returns
///
/// - `bool` - `true` when the suggestion belongs in the filtered list.
fn matches_lowered(option: &EuvAutoCompleteOption, lowered_query: &str) -> bool {
    if lowered_query.is_empty() {
        return true;
    }
    option.label.to_lowercase().contains(lowered_query)
        || option.value.to_lowercase().contains(lowered_query)
}

/// Returns the suggestion that carries the active marker.
///
/// The active suggestion is the one whose label or value equals the typed
/// text exactly; when no suggestion matches exactly the first one in the
/// filtered list is active.
///
/// # Arguments
///
/// - `&'a [EuvAutoCompleteOption]` - The suggestions left after filtering.
/// - `&str` - The typed text.
///
/// # Returns
///
/// - `Option<&'a EuvAutoCompleteOption>` - The active suggestion, or `None`
///   when the filtered list is empty.
pub fn auto_complete_active<'a>(
    filtered: &'a [EuvAutoCompleteOption],
    query: &str,
) -> Option<&'a EuvAutoCompleteOption> {
    let exact: Option<&'a EuvAutoCompleteOption> = filtered
        .iter()
        .find(|option: &&EuvAutoCompleteOption| option.label == query || option.value == query);
    exact.or_else(|| filtered.first())
}

/// Returns the active suggestion index for the current query.
///
/// # Arguments
///
/// - `&[EuvAutoCompleteOption]` - The suggestions left after filtering.
/// - `&str` - The typed text.
///
/// # Returns
///
/// - `Option<usize>` - The active option index, or `None` when no options remain.
fn auto_complete_active_index(filtered: &[EuvAutoCompleteOption], query: &str) -> Option<usize> {
    let active: Option<&EuvAutoCompleteOption> = auto_complete_active(filtered, query);
    active.and_then(|active_option: &EuvAutoCompleteOption| {
        filtered.iter().position(|option: &EuvAutoCompleteOption| {
            option.value == active_option.value && option.label == active_option.label
        })
    })
}

/// Builds the input handler of the auto-complete field.
///
/// The handler reads the value off the input element, publishes it to the
/// caller-owned signal and opens the suggestion panel as soon as the field
/// holds text and there is something to suggest.
///
/// # Arguments
///
/// - `Signal<String>` - The signal holding the text in the field.
/// - `Signal<bool>` - The panel's open state.
/// - `Signal<Option<usize>>` - The active suggestion index.
/// - `bool` - Whether the option list holds any suggestion at all.
/// - `bool` - Whether the input is editable.
/// - `Option<Rc<dyn Fn(&'static str)>>` - The callback receiving the typed text.
///
/// # Returns
///
/// - `Option<Rc<dyn Fn(Event)>>` - The input handler of the field.
fn on_auto_complete_input(
    value: Signal<String>,
    open: Signal<bool>,
    active_index: Signal<Option<usize>>,
    has_options: bool,
    can_edit: bool,
    on_change: Option<Rc<dyn Fn(&'static str)>>,
) -> Option<Rc<dyn Fn(Event)>> {
    Some(Rc::new(move |event: Event| {
        if !can_edit {
            return;
        }
        let reported: Option<String> = event.target().and_then(|target: EventTarget| {
            if let Ok(input) = target.dyn_into::<HtmlInputElement>() {
                return Some(input.value());
            }
            None
        });
        let Some(reported) = reported else {
            return;
        };
        value.set(reported.clone());
        open.set(has_options && !reported.is_empty());
        active_index.set(None);
        if let Some(callback) = &on_change {
            let leaked: &'static str = Box::leak(reported.into_boxed_str());
            callback(leaked);
        }
    }))
}

/// Builds the click handler of one suggestion.
///
/// The handler publishes the picked value, closes the panel and notifies the
/// caller that a suggestion was chosen.
///
/// # Arguments
///
/// - `Signal<String>` - The signal holding the text in the field.
/// - `Signal<bool>` - The panel's open state.
/// - `Signal<Option<usize>>` - The active suggestion index.
/// - `&'static str` - The value of the picked suggestion.
/// - `Option<Rc<dyn Fn(&'static str)>>` - The callback receiving the value.
/// - `bool` - Whether the component is disabled.
///
/// # Returns
///
/// - `Option<Rc<dyn Fn(Event)>>` - The click handler of the suggestion.
fn on_auto_complete_select(
    value: Signal<String>,
    open: Signal<bool>,
    active_index: Signal<Option<usize>>,
    option_value: &'static str,
    on_select: Option<Rc<dyn Fn(&'static str)>>,
    disabled: bool,
) -> Option<Rc<dyn Fn(Event)>> {
    if disabled {
        return None;
    }
    Some(Rc::new(move |_event: Event| {
        value.set(String::from(option_value));
        open.set(false);
        active_index.set(None);
        if let Some(callback) = &on_select {
            callback(option_value);
        }
    }))
}

/// Builds the keyboard handler of the editable combobox input.
///
/// # Arguments
///
/// - `Signal<String>` - The signal holding the text in the field.
/// - `Signal<bool>` - The panel's open state.
/// - `Signal<Option<usize>>` - The active suggestion index.
/// - `Vec<EuvAutoCompleteOption>` - The suggestions currently in the popup.
/// - `Option<Rc<dyn Fn(&'static str)>>` - The callback receiving a picked value.
/// - `bool` - Whether the component is disabled.
///
/// # Returns
///
/// - `Option<Rc<dyn Fn(Event)>>` - The keyboard handler of the field.
fn on_auto_complete_keydown(
    value: Signal<String>,
    open: Signal<bool>,
    active_index: Signal<Option<usize>>,
    filtered: Vec<EuvAutoCompleteOption>,
    on_select: Option<Rc<dyn Fn(&'static str)>>,
    disabled: bool,
) -> Option<Rc<dyn Fn(Event)>> {
    Some(Rc::new(move |event: Event| {
        if disabled {
            return;
        }
        let Ok(keyboard_event) = event.dyn_into::<KeyboardEvent>() else {
            return;
        };
        if keyboard_event.ctrl_key()
            || keyboard_event.shift_key()
            || keyboard_event.alt_key()
            || keyboard_event.meta_key()
        {
            return;
        }
        let key: String = keyboard_event.key();
        let is_open: bool = open.get();
        let query: String = value.get();
        let preferred_index: Option<usize> = auto_complete_active_index(&filtered, &query);
        match key.as_str() {
            AUTO_COMPLETE_KEY_ARROW_DOWN => {
                if filtered.is_empty() {
                    return;
                }
                keyboard_event.prevent_default();
                let next_index: Option<usize> = if is_open {
                    match active_index
                        .get()
                        .filter(|index: &usize| *index < filtered.len())
                    {
                        Some(index) if index + 1 < filtered.len() => Some(index + 1),
                        Some(_) => None,
                        None => Some(0),
                    }
                } else {
                    preferred_index.or(Some(0))
                };
                active_index.set(next_index);
                open.set(true);
            }
            AUTO_COMPLETE_KEY_ARROW_UP => {
                if filtered.is_empty() {
                    return;
                }
                keyboard_event.prevent_default();
                let next_index: Option<usize> = if is_open {
                    match active_index
                        .get()
                        .filter(|index: &usize| *index < filtered.len())
                    {
                        Some(index) if index > 0 => Some(index - 1),
                        Some(_) => None,
                        None => Some(filtered.len() - 1),
                    }
                } else {
                    Some(filtered.len() - 1)
                };
                active_index.set(next_index);
                open.set(true);
            }
            AUTO_COMPLETE_KEY_ENTER => {
                if !is_open || keyboard_event.is_composing() || keyboard_event.key_code() == 229 {
                    return;
                }
                let selected_option: Option<&EuvAutoCompleteOption> = active_index
                    .get()
                    .filter(|index: &usize| *index < filtered.len())
                    .and_then(|index: usize| filtered.get(index));
                let Some(option) = selected_option else {
                    open.set(false);
                    active_index.set(None);
                    return;
                };
                keyboard_event.prevent_default();
                value.set(String::from(option.value));
                open.set(false);
                active_index.set(None);
                if let Some(callback) = &on_select {
                    callback(option.value);
                }
            }
            AUTO_COMPLETE_KEY_ESCAPE => {
                if is_open {
                    keyboard_event.prevent_default();
                    open.set(false);
                    active_index.set(None);
                }
            }
            AUTO_COMPLETE_KEY_TAB if is_open => {
                open.set(false);
                active_index.set(None);
            }
            _ => {}
        }
    }))
}

/// Prevents a suggestion click from moving focus away from the input.
///
/// # Returns
///
/// - `Option<Rc<dyn Fn(Event)>>` - The mousedown handler of a suggestion.
fn on_auto_complete_option_mousedown() -> Option<Rc<dyn Fn(Event)>> {
    Some(Rc::new(|event: Event| event.prevent_default()))
}

/// Builds the pointer-move handler that highlights one suggestion.
///
/// # Arguments
///
/// - `Signal<Option<usize>>` - The active suggestion index.
/// - `usize` - The suggestion index under the pointer.
/// - `bool` - Whether the component is disabled.
///
/// # Returns
///
/// - `Option<Rc<dyn Fn(Event)>>` - The pointer-move handler of the suggestion.
fn on_auto_complete_option_pointer_move(
    active_index: Signal<Option<usize>>,
    option_index: usize,
    disabled: bool,
) -> Option<Rc<dyn Fn(Event)>> {
    if disabled {
        return None;
    }
    Some(Rc::new(move |_event: Event| {
        active_index.set(Some(option_index))
    }))
}

/// Converts a state flag to the DOM renderer's native boolean value.
///
/// # Arguments
///
/// - `bool` - The state flag to render.
///
/// # Returns
///
/// - `&'static str` - `"true"` when enabled, or an empty value when disabled.
fn auto_complete_boolean_attr(flag: bool) -> &'static str {
    if flag {
        AUTO_COMPLETE_ARIA_TRUE
    } else {
        AUTO_COMPLETE_ATTRIBUTE_EMPTY
    }
}

/// Renders the native input, omitting an empty `form` attribute so ancestor
/// form ownership remains intact.
///
/// # Arguments
///
/// - `EuvAutoCompleteInputProps` - The input values, states and handlers.
///
/// # Returns
///
/// - `VirtualNode` - The labeled combobox input.
fn auto_complete_input(props: EuvAutoCompleteInputProps) -> VirtualNode {
    let EuvAutoCompleteInputProps {
        id,
        name,
        form,
        autocomplete,
        aria_label,
        aria_describedby,
        invalid,
        required,
        disabled,
        read_only,
        panel_open,
        listbox_id,
        active_descendant_id,
        placeholder,
        value,
        input_class,
        default_class,
        invalid_class,
        disabled_class,
        on_input,
        on_keydown,
    }: EuvAutoCompleteInputProps = props;
    let required_attribute: &'static str = auto_complete_boolean_attr(required);
    let disabled_attribute: &'static str = auto_complete_boolean_attr(disabled);
    let read_only_attribute: &'static str = auto_complete_boolean_attr(read_only);
    let has_active_descendant: bool = !active_descendant_id.is_empty();
    if form.is_empty() {
        if has_active_descendant {
            html! {
                input {
                    "data-slot": "auto-complete-input"
                    id: id
                    type: "text"
                    name: name
                    autocomplete: autocomplete
                    role: AUTO_COMPLETE_ROLE_COMBOBOX
                    "aria-autocomplete": AUTO_COMPLETE_ARIA_AUTOCOMPLETE_LIST
                    "aria-haspopup": AUTO_COMPLETE_ROLE_LISTBOX
                    "aria-controls": listbox_id
                    "aria-label": aria_label
                    "aria-describedby": aria_describedby
                    "aria-invalid": if invalid {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-required": if required {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-disabled": if disabled {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-readonly": if read_only {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-expanded": if panel_open {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-activedescendant": active_descendant_id
                    placeholder: placeholder
                    value: value
                    required: required_attribute
                    disabled: disabled_attribute
                    readonly: read_only_attribute
                    class: input_class
                    class: default_class
                    class: invalid_class
                    class: disabled_class
                    oninput: on_input
                    onkeydown: on_keydown
                }
            }
        } else {
            html! {
                input {
                    "data-slot": "auto-complete-input"
                    id: id
                    type: "text"
                    name: name
                    autocomplete: autocomplete
                    role: AUTO_COMPLETE_ROLE_COMBOBOX
                    "aria-autocomplete": AUTO_COMPLETE_ARIA_AUTOCOMPLETE_LIST
                    "aria-haspopup": AUTO_COMPLETE_ROLE_LISTBOX
                    "aria-controls": listbox_id
                    "aria-label": aria_label
                    "aria-describedby": aria_describedby
                    "aria-invalid": if invalid {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-required": if required {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-disabled": if disabled {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-readonly": if read_only {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-expanded": if panel_open {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    placeholder: placeholder
                    value: value
                    required: required_attribute
                    disabled: disabled_attribute
                    readonly: read_only_attribute
                    class: input_class
                    class: default_class
                    class: invalid_class
                    class: disabled_class
                    oninput: on_input
                    onkeydown: on_keydown
                }
            }
        }
    } else {
        if has_active_descendant {
            html! {
                input {
                    "data-slot": "auto-complete-input"
                    id: id
                    type: "text"
                    name: name
                    form: form
                    autocomplete: autocomplete
                    role: AUTO_COMPLETE_ROLE_COMBOBOX
                    "aria-autocomplete": AUTO_COMPLETE_ARIA_AUTOCOMPLETE_LIST
                    "aria-haspopup": AUTO_COMPLETE_ROLE_LISTBOX
                    "aria-controls": listbox_id
                    "aria-label": aria_label
                    "aria-describedby": aria_describedby
                    "aria-invalid": if invalid {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-required": if required {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-disabled": if disabled {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-readonly": if read_only {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-expanded": if panel_open {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-activedescendant": active_descendant_id
                    placeholder: placeholder
                    value: value
                    required: required_attribute
                    disabled: disabled_attribute
                    readonly: read_only_attribute
                    class: input_class
                    class: default_class
                    class: invalid_class
                    class: disabled_class
                    oninput: on_input
                    onkeydown: on_keydown
                }
            }
        } else {
            html! {
                input {
                    "data-slot": "auto-complete-input"
                    id: id
                    type: "text"
                    name: name
                    form: form
                    autocomplete: autocomplete
                    role: AUTO_COMPLETE_ROLE_COMBOBOX
                    "aria-autocomplete": AUTO_COMPLETE_ARIA_AUTOCOMPLETE_LIST
                    "aria-haspopup": AUTO_COMPLETE_ROLE_LISTBOX
                    "aria-controls": listbox_id
                    "aria-label": aria_label
                    "aria-describedby": aria_describedby
                    "aria-invalid": if invalid {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-required": if required {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-disabled": if disabled {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-readonly": if read_only {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-expanded": if panel_open {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    placeholder: placeholder
                    value: value
                    required: required_attribute
                    disabled: disabled_attribute
                    readonly: read_only_attribute
                    class: input_class
                    class: default_class
                    class: invalid_class
                    class: disabled_class
                    oninput: on_input
                    onkeydown: on_keydown
                }
            }
        }
    }
}

/// A text field with a filtered list of suggestions.
///
/// The component renders a `c_euv_auto_complete` wrapper holding a real
/// `<input type="text">` and the suggestion panel. The panel is always
/// mounted; opening and closing it is a reactive class swap between
/// `c_euv_auto_complete_panel_open` and `c_euv_auto_complete_panel_closed`,
/// so the browser never has to rebuild the suggestion list.
///
/// The suggestions are the options whose label or value contains the typed
/// text, compared case-insensitively. The panel stays closed while the field
/// is empty or while there is nothing to suggest at all; when the field
/// holds text that matches no suggestion the panel shows a single
/// `c_euv_auto_complete_empty` row instead of an empty dropdown.
///
/// The text in the field lives in a caller-owned [`Signal`], so the component
/// takes part in two-way binding. Picking a suggestion writes its value into
/// that signal, notifies `on_select` and closes the panel.
///
/// # Arguments
///
/// - `VirtualNode<EuvAutoCompleteProps>` - The props node carrying the
///   suggestions, the text and the callbacks.
///
/// # Returns
///
/// - `VirtualNode` - The text field with its suggestion panel.
#[component]
pub fn euv_auto_complete(node: VirtualNode<EuvAutoCompleteProps>) -> VirtualNode {
    let EuvAutoCompleteProps {
        options,
        value,
        placeholder,
        label: label_text,
        id,
        name,
        form,
        autocomplete,
        required,
        invalid,
        disabled,
        read_only,
        aria_label,
        aria_describedby,
        on_change,
        on_select,
    }: EuvAutoCompleteProps = node.try_get_props().unwrap_or_default();
    let open: Signal<bool> = App::use_signal(|| false);
    let active_index_signal: Signal<Option<usize>> = App::use_signal(|| None);
    let input_id: UseId = use_id("auto-complete");
    let input_id_value: String = if id.is_empty() {
        input_id.get_value().get()
    } else {
        String::from(id)
    };
    let input_label_for: String = input_id_value.clone();
    let effective_aria_label: &'static str = if aria_label.is_empty() {
        label_text
    } else {
        aria_label
    };
    let effective_autocomplete: &'static str = if autocomplete.is_empty() {
        AUTO_COMPLETE_AUTOCOMPLETE_DEFAULT
    } else {
        autocomplete
    };
    let listbox_id: String = format!("{input_id_value}{AUTO_COMPLETE_LISTBOX_ID_SUFFIX}");
    let initial_value: String = value.get();
    let reset_value_signal: Signal<String> = value;
    let reset_open_signal: Signal<bool> = open;
    let reset_active_index_signal: Signal<Option<usize>> = active_index_signal;
    let reset_input_id: String = input_id_value.clone();
    let reset_callback: Rc<dyn Fn()> = Rc::new(move || {
        let reset_value: String = initial_value.clone();
        reset_value_signal.set(reset_value.clone());
        reset_open_signal.set(false);
        reset_active_index_signal.set(None);
        let input: Option<HtmlInputElement> = window()
            .and_then(|window: Window| window.document())
            .and_then(|document: Document| document.get_element_by_id(&reset_input_id))
            .and_then(|element: Element| element.dyn_into::<HtmlInputElement>().ok());
        if let Some(input) = input {
            input.set_value(&reset_value);
        }
    });
    use_form_reset(input_id_value.clone(), form, reset_callback);
    let query: String = value.get();
    let lowered_query: String = query.to_lowercase();
    let has_options: bool = !options.is_empty();
    let filtered: Vec<EuvAutoCompleteOption> = options
        .iter()
        .filter(|option: &&EuvAutoCompleteOption| matches_lowered(option, &lowered_query))
        .copied()
        .collect();
    let panel_open: bool = open.get() && !disabled;
    let active_index: Option<usize> = if panel_open && !filtered.is_empty() {
        active_index_signal
            .get()
            .filter(|index: &usize| *index < filtered.len())
    } else {
        None
    };
    let active_descendant_id: String = active_index
        .map(|index: usize| format!("{input_id_value}{AUTO_COMPLETE_OPTION_ID_SUFFIX}{index}"))
        .unwrap_or_default();
    let invalid_input_class: Css = if invalid {
        c_euv_auto_complete_input_invalid().clone()
    } else {
        Css::default()
    };
    let disabled_input_class: Css = if disabled {
        c_euv_auto_complete_input_disabled().clone()
    } else {
        Css::default()
    };
    let default_input_class: Css = c_euv_auto_complete_input_default().clone();
    let rows: Vec<VirtualNode> = filtered
        .iter()
        .enumerate()
        .map(|(index, option): (usize, &EuvAutoCompleteOption)| {
            let option_value: &'static str = option.value;
            let option_label: &'static str = option.label;
            let is_active: bool = active_index == Some(index);
            let is_selected: bool = option_value == query;
            let option_id: String =
                format!("{input_id_value}{AUTO_COMPLETE_OPTION_ID_SUFFIX}{index}");
            let option_class: fn() -> &'static Css = if is_active {
                c_euv_auto_complete_option_active
            } else {
                c_euv_auto_complete_option
            };
            html! {
                div {
                    id: option_id
                    role: AUTO_COMPLETE_ROLE_OPTION
                    "aria-disabled": if disabled {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    "aria-selected": if is_selected {
                        AUTO_COMPLETE_ARIA_TRUE
                    } else {
                        AUTO_COMPLETE_ARIA_FALSE
                    }
                    class: option_class()
                    onpointermove: on_auto_complete_option_pointer_move(
                        active_index_signal,
                        index,
                        disabled
                    )
                    onpointerdown: on_auto_complete_option_mousedown()
                    onmousedown: on_auto_complete_option_mousedown()
                    onclick: on_auto_complete_select(
                    value,
                    open,
                    active_index_signal,
                    option_value,
                    on_select.clone(),
                    disabled
                    )
                    option_label
                }
            }
        })
        .collect();
    let has_no_matches: bool = rows.is_empty() && has_options && !query.is_empty();
    let input_node: VirtualNode = auto_complete_input(EuvAutoCompleteInputProps {
        id: input_id_value.clone(),
        name,
        form,
        autocomplete: effective_autocomplete,
        aria_label: effective_aria_label,
        aria_describedby,
        invalid,
        required,
        disabled,
        read_only,
        panel_open,
        listbox_id: listbox_id.clone(),
        active_descendant_id,
        placeholder,
        value,
        input_class: c_euv_auto_complete_input().clone(),
        default_class: default_input_class,
        invalid_class: invalid_input_class,
        disabled_class: disabled_input_class,
        on_input: on_auto_complete_input(
            value,
            open,
            active_index_signal,
            has_options,
            !disabled && !read_only,
            on_change.clone(),
        ),
        on_keydown: on_auto_complete_keydown(
            value,
            open,
            active_index_signal,
            filtered.clone(),
            on_select.clone(),
            disabled,
        ),
    });
    html! {
        div {
            "data-slot": "auto-complete"
            "data-disabled": if disabled {
                AUTO_COMPLETE_ARIA_TRUE
            } else {
                AUTO_COMPLETE_ARIA_FALSE
            }
            "data-invalid": if invalid {
                AUTO_COMPLETE_ARIA_TRUE
            } else {
                AUTO_COMPLETE_ARIA_FALSE
            }
            "data-readonly": if read_only {
                AUTO_COMPLETE_ARIA_TRUE
            } else {
                AUTO_COMPLETE_ARIA_FALSE
            }
            "data-required": if required {
                AUTO_COMPLETE_ARIA_TRUE
            } else {
                AUTO_COMPLETE_ARIA_FALSE
            }
            class: c_euv_auto_complete()
            if !label_text.is_empty() {
                label {
                    r#for: input_label_for.clone()
                    class: c_form_label()
                    label_text
                }
            }
            input_node
            div {
                "aria-hidden": if panel_open {
                    AUTO_COMPLETE_ARIA_FALSE
                } else {
                    AUTO_COMPLETE_ARIA_TRUE
                }
                class: c_euv_auto_complete_panel()
                class: if panel_open {
                    c_euv_auto_complete_panel_open()
                } else {
                    c_euv_auto_complete_panel_closed()
                }
                div {
                    id: listbox_id
                    role: AUTO_COMPLETE_ROLE_LISTBOX
                    rows
                }
                div {
                    role: AUTO_COMPLETE_ROLE_STATUS
                    "aria-live": AUTO_COMPLETE_ARIA_LIVE_POLITE
                    "aria-atomic": AUTO_COMPLETE_ARIA_TRUE
                    class: if has_no_matches {
                        c_euv_auto_complete_empty().clone()
                    } else {
                        Css::default()
                    }
                    if has_no_matches {
                        NO_MATCHES_TEXT
                    }
                }
            }
        }
    }
}