commit
b7a52d3e3d
|
@ -33,7 +33,33 @@ pub fn global_attrs(span: Span) -> StringyMap<Ident, TokenStream> {
|
||||||
insert("tabindex", "isize");
|
insert("tabindex", "isize");
|
||||||
insert("title", "String");
|
insert("title", "String");
|
||||||
|
|
||||||
// FIXME ARIA and XML attrs missing
|
// ARIA
|
||||||
|
insert("aria_autocomplete", "String");
|
||||||
|
insert("aria_checked", "crate::types::Bool");
|
||||||
|
insert("aria_disabled", "crate::types::Bool");
|
||||||
|
insert("aria_errormessage", "String");
|
||||||
|
insert("aria_expanded", "crate::types::Bool");
|
||||||
|
insert("aria_haspopup", "crate::types::Bool");
|
||||||
|
insert("aria_hidden", "crate::types::Bool");
|
||||||
|
insert("aria_invalid", "crate::types::Bool");
|
||||||
|
insert("aria_label", "String");
|
||||||
|
insert("aria_modal", "crate::types::Bool");
|
||||||
|
insert("aria_multiline", "crate::types::Bool");
|
||||||
|
insert("aria_multiselectable", "crate::types::Bool");
|
||||||
|
insert("aria_orientation", "String"); // TODO Only supports some values https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-orientation
|
||||||
|
insert("aria_placeholder", "String");
|
||||||
|
insert("aria_pressed", "crate::types::Bool");
|
||||||
|
insert("aria_readonly", "crate::types::Bool");
|
||||||
|
insert("aria_required", "crate::types::Bool");
|
||||||
|
insert("aria_selected", "crate::types::Bool");
|
||||||
|
insert("aria_placeholder", "String");
|
||||||
|
insert("aria_sort", "String"); // TODO only supports some values
|
||||||
|
insert("aria_valuemax", "isize");
|
||||||
|
insert("aria_valuemin", "isize");
|
||||||
|
insert("aria_valuenow", "isize");
|
||||||
|
insert("aria_valuetext", "String");
|
||||||
|
|
||||||
|
// FIXME XML attrs missing
|
||||||
}
|
}
|
||||||
attrs
|
attrs
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ impl Declare {
|
||||||
pub struct #elem_name<T> where T: crate::OutputType + Send {
|
pub struct #elem_name<T> where T: crate::OutputType + Send {
|
||||||
pub attrs: #attr_type_name,
|
pub attrs: #attr_type_name,
|
||||||
pub data_attributes: Vec<(&'static str, String)>,
|
pub data_attributes: Vec<(&'static str, String)>,
|
||||||
|
pub aria_attributes: Vec<(&'static str, String)>,
|
||||||
pub events: T::Events,
|
pub events: T::Events,
|
||||||
#body
|
#body
|
||||||
}
|
}
|
||||||
|
@ -127,6 +128,7 @@ impl Declare {
|
||||||
attrs: #attr_type_name { #attrs },
|
attrs: #attr_type_name { #attrs },
|
||||||
));
|
));
|
||||||
body.extend(quote!(data_attributes: Vec::new(),));
|
body.extend(quote!(data_attributes: Vec::new(),));
|
||||||
|
body.extend(quote!(aria_attributes: Vec::new(),));
|
||||||
|
|
||||||
for (child_name, _, _) in self.req_children() {
|
for (child_name, _, _) in self.req_children() {
|
||||||
body.extend(quote!( #child_name, ));
|
body.extend(quote!( #child_name, ));
|
||||||
|
@ -175,6 +177,7 @@ impl Declare {
|
||||||
let mut attributes = Vec::new();
|
let mut attributes = Vec::new();
|
||||||
#push_attrs
|
#push_attrs
|
||||||
attributes.extend(self.data_attributes.clone());
|
attributes.extend(self.data_attributes.clone());
|
||||||
|
attributes.extend(self.aria_attributes.clone());
|
||||||
|
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
#req_children
|
#req_children
|
||||||
|
@ -240,6 +243,10 @@ impl Declare {
|
||||||
for (key, value) in &self.data_attributes {
|
for (key, value) in &self.data_attributes {
|
||||||
out.push((key, value.to_string()));
|
out.push((key, value.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (key, value) in &self.aria_attributes {
|
||||||
|
out.push((key, value.to_string()));
|
||||||
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,6 +360,10 @@ impl Declare {
|
||||||
write!(f, " data-{}=\"{}\"", key,
|
write!(f, " data-{}=\"{}\"", key,
|
||||||
crate::escape_html_attribute(value.to_string()))?;
|
crate::escape_html_attribute(value.to_string()))?;
|
||||||
}
|
}
|
||||||
|
for (key, value) in &self.aria_attributes {
|
||||||
|
write!(f, " aria-{}=\"{}\"", key,
|
||||||
|
crate::escape_html_attribute(value.to_string()))?;
|
||||||
|
}
|
||||||
write!(f, "{}", self.events)?;
|
write!(f, "{}", self.events)?;
|
||||||
#print_children
|
#print_children
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,21 @@ fn extract_event_handlers(
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_aria_attributes(
|
||||||
|
attrs: &mut StringyMap<Ident, TokenTree>,
|
||||||
|
) -> StringyMap<String, TokenTree> {
|
||||||
|
let mut data = StringyMap::new();
|
||||||
|
let keys: Vec<Ident> = attrs.keys().cloned().collect();
|
||||||
|
for key in keys {
|
||||||
|
let key_name = key.to_string();
|
||||||
|
if let Some(key_name) = key_name.strip_prefix("aria_") {
|
||||||
|
let value = attrs.remove(&key).unwrap();
|
||||||
|
data.insert(key_name.to_string(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data
|
||||||
|
}
|
||||||
|
|
||||||
fn process_value(value: &TokenTree) -> TokenStream {
|
fn process_value(value: &TokenTree) -> TokenStream {
|
||||||
match value {
|
match value {
|
||||||
TokenTree::Group(g) if g.delimiter() == Delimiter::Bracket => {
|
TokenTree::Group(g) if g.delimiter() == Delimiter::Bracket => {
|
||||||
|
@ -146,6 +161,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
let events = extract_event_handlers(&mut self.attributes);
|
let events = extract_event_handlers(&mut self.attributes);
|
||||||
let data_attrs = extract_data_attrs(&mut self.attributes);
|
let data_attrs = extract_data_attrs(&mut self.attributes);
|
||||||
|
let aria_attrs = extract_aria_attributes(&mut self.attributes);
|
||||||
let attrs = self.attributes.iter().map(|(key, value)| {
|
let attrs = self.attributes.iter().map(|(key, value)| {
|
||||||
(
|
(
|
||||||
key.to_string(),
|
key.to_string(),
|
||||||
|
@ -217,6 +233,16 @@ impl Element {
|
||||||
element.data_attributes.push((#key, #value.into()));
|
element.data_attributes.push((#key, #value.into()));
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (key, value) in aria_attrs
|
||||||
|
.iter()
|
||||||
|
.map(|(k, v)| (TokenTree::from(Literal::string(k)), v.clone()))
|
||||||
|
{
|
||||||
|
body.extend(quote!(
|
||||||
|
element.aria_attributes.push((#key, #value.into()));
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
body.extend(opt_children);
|
body.extend(opt_children);
|
||||||
|
|
||||||
for (key, value) in events.iter() {
|
for (key, value) in events.iter() {
|
||||||
|
|
|
@ -474,3 +474,17 @@ fn test_meta_tags() {
|
||||||
frag.to_string()
|
frag.to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_aria() {
|
||||||
|
use crate as axohtml;
|
||||||
|
use crate::{dom::DOMTree, html};
|
||||||
|
|
||||||
|
let frag: DOMTree<String> = html!(<div aria_hidden="true" aria_label="hello" />
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
"<div aria-hidden=\"true\" aria-label=\"hello\"></div>",
|
||||||
|
frag.to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue