queryAllByRole
List<
Finds all elements with the given ARIA role.
Implementation
List<DomNode> queryAllByRole(String role, {String? name}) {
final implicitRoleElements = <String, List<String>>{
'button': ['button', '[type="button"]', '[type="submit"]'],
'textbox': ['input:not([type])', 'input[type="text"]', 'textarea'],
'checkbox': ['input[type="checkbox"]'],
'radio': ['input[type="radio"]'],
'link': ['a[href]'],
'heading': ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
'list': ['ul', 'ol'],
'listitem': ['li'],
'img': ['img[alt]'],
'navigation': ['nav'],
'main': ['main'],
'banner': ['header'],
'contentinfo': ['footer'],
'region': ['section[aria-label]', 'section[aria-labelledby]'],
};
final selectors = implicitRoleElements[role] ?? [];
final explicitRoleSelector = '[role="$role"]';
final allSelectors = [...selectors, explicitRoleSelector].join(', ');
final results = allSelectors.isNotEmpty
? _container.querySelectorAll(allSelectors)
: <DomNode>[];
return (name != null)
? results.where((el) {
final ariaLabel = el.getAttribute('aria-label');
final textContent = el.textContent;
return ariaLabel == name || textContent == name;
}).toList()
: results;
}