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
@@ -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