[IMP] core: _validate_fa_class_accessibility cleanups

* add t-out to set of text-generation attributes
* fix comment location
* don't handroll `iterancestors()`
* only check the `@string` on the toplevel button, doesn't really make
  sense that a button would contain a button in the first place (in
  fact it's not allowed per the HTML spec, a button can only contain
  *non-interactive phrasing content* cf 4.10.6)

Part-of: odoo/odoo#76581
This commit is contained in:
Xavier Morel
2021-09-15 15:22:57 +00:00
parent 97ed053b31
commit 78d1b9591c
+8 -10
View File
@@ -1749,7 +1749,7 @@ actual arch.
valid_aria_attrs = {
*att_names('title'), *att_names('aria-label'), *att_names('aria-labelledby'),
}
valid_t_attrs = {'t-value', 't-raw', 't-field', 't-esc'}
valid_t_attrs = {'t-value', 't-raw', 't-field', 't-esc', 't-out'}
## Following or preceding text
if (node.tail or '').strip() or (node.getparent().text or '').strip():
@@ -1769,15 +1769,15 @@ actual arch.
if has_text(node.getnext()) or has_text(node.getprevious()):
return
## Aria label can be on ancestors
def has_title_or_aria_label(node):
return any(node.get(attr) for attr in valid_aria_attrs)
parent = node.getparent()
while parent is not None:
if has_title_or_aria_label(parent):
return
parent = parent.getparent()
## Aria label can be on ancestors
if any(map(has_title_or_aria_label, node.iterancestors())):
return
if node.get('string'):
return
## And we ignore all elements with describing in children
def contains_description(node, depth=0):
@@ -1789,8 +1789,6 @@ actual arch.
return True
if node.tag in ('label', 'field'):
return True
if node.tag == 'button' and node.get('string'):
return True
if node.text: # not sure, does it match *[text()]
return True
return any(contains_description(child, depth+1) for child in node)
@@ -1798,7 +1796,7 @@ actual arch.
if contains_description(node):
return
msg = ('%s must have title in its tag, parents, descendants or have text')
msg = '%s must have title in its tag, parents, descendants or have text'
self._log_view_warning(msg % description, node)
def _get_domain_identifiers(self, node, domain, use, expr=None):