Forms · Select and TextInput label: the name assistive technology reads, drawn nowhere
This commit is contained in:
4 files changed
+25
-3
No files matched your search
@@ -252,6 +252,7 @@ pub struct Select {
|
||||
choices: Vec<Choice>,
|
||||
selected: Option<SharedString>,
|
||||
placeholder: SharedString,
|
||||
label: Option<SharedString>,
|
||||
size: ControlSize,
|
||||
disabled: bool,
|
||||
on_change: Option<OnValue>,
|
||||
@@ -264,12 +265,19 @@ impl Select {
|
||||
choices: choices.into_iter().collect(),
|
||||
selected: None,
|
||||
placeholder: SharedString::from("Choose…"),
|
||||
label: None,
|
||||
size: ControlSize::default(),
|
||||
disabled: false,
|
||||
on_change: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The name assistive technology reads; nothing is drawn.
|
||||
pub fn label(mut self, text: impl Into<SharedString>) -> Self {
|
||||
self.label = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn selected(mut self, value: impl Into<SharedString>) -> Self {
|
||||
self.selected = Some(value.into());
|
||||
self
|
||||
@@ -329,6 +337,7 @@ impl RenderOnce for Select {
|
||||
)
|
||||
.role(Role::ComboBox)
|
||||
.aria_placeholder(self.placeholder.clone())
|
||||
.when_some(self.label.clone(), |trigger, label| trigger.aria_label(label))
|
||||
.when_some(shown.as_ref(), |trigger, choice| {
|
||||
trigger.aria_value(choice.label.clone())
|
||||
})
|
||||
|
||||
@@ -360,9 +360,13 @@ impl Render for TextInput {
|
||||
div()
|
||||
.id("ely-text-input")
|
||||
.role(Role::TextInput)
|
||||
.when(!self.placeholder.is_empty(), |el| {
|
||||
el.aria_label(self.placeholder.clone())
|
||||
})
|
||||
.when_some(
|
||||
[&self.label, &self.placeholder]
|
||||
.into_iter()
|
||||
.find(|name| !name.is_empty())
|
||||
.cloned(),
|
||||
|el, name| el.aria_label(name),
|
||||
)
|
||||
.when(!self.masked, |el| el.aria_value(self.text.clone()))
|
||||
.key_context(CONTEXT)
|
||||
.track_focus(&self.focus)
|
||||
|
||||
@@ -51,6 +51,7 @@ pub struct TextInput {
|
||||
focus: FocusHandle,
|
||||
text: String,
|
||||
placeholder: SharedString,
|
||||
label: SharedString,
|
||||
selection: Range<usize>,
|
||||
reversed: bool,
|
||||
marked: Option<Range<usize>>,
|
||||
@@ -105,6 +106,7 @@ impl TextInput {
|
||||
focus,
|
||||
text: String::new(),
|
||||
placeholder: SharedString::default(),
|
||||
label: SharedString::default(),
|
||||
selection: 0..0,
|
||||
reversed: false,
|
||||
marked: None,
|
||||
@@ -141,6 +143,12 @@ impl TextInput {
|
||||
self
|
||||
}
|
||||
|
||||
/// The name assistive technology reads; the placeholder otherwise.
|
||||
pub fn label(mut self, text: impl Into<SharedString>) -> Self {
|
||||
self.label = text.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows bullets instead of the text, and keeps it off the clipboard.
|
||||
pub fn masked(mut self) -> Self {
|
||||
self.masked = true;
|
||||
|
||||
Reference in new issue
Block a user