euv_ui/component/auto_complete/view/struct.rs
1use super::*;
2
3/// One suggestion offered by the [`euv_auto_complete`] component.
4///
5/// The `value` is what lands in the field when the suggestion is picked,
6/// while the `label` is what the user reads in the suggestion list.
7#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
8pub struct EuvAutoCompleteOption {
9 /// The value written into the field when the option is picked.
10 #[get(type(copy))]
11 pub value: &'static str,
12 /// The text shown in the suggestion list.
13 #[get(type(copy))]
14 pub label: &'static str,
15}
16
17/// Props for the [`euv_auto_complete`] component.
18///
19/// The text in the field lives in a caller-owned [`Signal`] so the component
20/// takes part in two-way binding; the open state of the suggestion panel is
21/// owned by the component itself.
22#[derive(Clone, CustomDebug, Default)]
23pub struct EuvAutoCompleteProps {
24 /// The suggestions offered to the user.
25 pub options: Vec<EuvAutoCompleteOption>,
26 /// The text currently held by the field.
27 pub value: Signal<String>,
28 /// The placeholder shown while the field is empty.
29 pub placeholder: &'static str,
30 /// The label rendered above the field.
31 ///
32 /// An empty string renders the field without a label.
33 pub label: &'static str,
34 /// The id used to associate the label with the input.
35 ///
36 /// An empty string uses the component-generated id.
37 pub id: &'static str,
38 /// The form field name submitted with the input value.
39 pub name: &'static str,
40 /// The id of the owning form; an empty value uses the nearest ancestor form.
41 pub form: &'static str,
42 /// The browser autofill hint; an empty value enables the browser default.
43 pub autocomplete: &'static str,
44 /// Whether the input participates in required form validation.
45 pub required: bool,
46 /// Whether the input is currently invalid.
47 pub invalid: bool,
48 /// Whether the input and suggestion list are disabled.
49 pub disabled: bool,
50 /// Whether the input text is read-only while suggestions remain selectable.
51 pub read_only: bool,
52 /// The accessible name used when no visible label is rendered.
53 pub aria_label: &'static str,
54 /// Space-separated ids naming the input's descriptive text.
55 pub aria_describedby: &'static str,
56 /// The callback invoked with the typed text after every change.
57 ///
58 /// The text is handed over as a `'static` slice, so the component
59 /// leaks one small string per distinct value the user types.
60 #[debug(skip)]
61 pub on_change: Option<Rc<dyn Fn(&'static str)>>,
62 /// The callback invoked with the value of the picked suggestion.
63 #[debug(skip)]
64 pub on_select: Option<Rc<dyn Fn(&'static str)>>,
65}
66
67/// Render-time attributes and handlers for the native AutoComplete input.
68pub(crate) struct EuvAutoCompleteInputProps {
69 /// The native input id.
70 pub(crate) id: String,
71 /// The form field name.
72 pub(crate) name: &'static str,
73 /// The optional external form id.
74 pub(crate) form: &'static str,
75 /// The browser autocomplete hint.
76 pub(crate) autocomplete: &'static str,
77 /// The input's accessible name.
78 pub(crate) aria_label: &'static str,
79 /// The input's descriptive ID references.
80 pub(crate) aria_describedby: &'static str,
81 /// Whether the input is invalid.
82 pub(crate) invalid: bool,
83 /// Whether the input is required.
84 pub(crate) required: bool,
85 /// Whether the input is disabled.
86 pub(crate) disabled: bool,
87 /// Whether the input is read-only.
88 pub(crate) read_only: bool,
89 /// Whether the suggestion panel is open.
90 pub(crate) panel_open: bool,
91 /// The id of the controlled suggestion list.
92 pub(crate) listbox_id: String,
93 /// The currently active suggestion id.
94 pub(crate) active_descendant_id: String,
95 /// The input placeholder.
96 pub(crate) placeholder: &'static str,
97 /// The caller-owned input value.
98 pub(crate) value: Signal<String>,
99 /// The base input style.
100 pub(crate) input_class: Css,
101 /// The compile-selected default input geometry.
102 pub(crate) default_class: Css,
103 /// The invalid-state input style.
104 pub(crate) invalid_class: Css,
105 /// The disabled-state input style.
106 pub(crate) disabled_class: Css,
107 /// The input handler.
108 pub(crate) on_input: Option<Rc<dyn Fn(Event)>>,
109 /// The keyboard handler.
110 pub(crate) on_keydown: Option<Rc<dyn Fn(Event)>>,
111}