Module: Dommy::Internal::AccessibleDescription

Defined in:
lib/dommy/internal/accessible_description.rb

Overview

Computes an element's WAI-ARIA accessible description — what WPT's test_driver.get_computed_label's description counterpart returns. The description sources, in precedence order, are aria-describedby, aria-description, then title. It reuses the accessible-name machinery to resolve the describedby IDREF list (each referenced element contributes its accessible NAME).

The one subtlety: title provides the accessible name when nothing else does, and provides the description otherwise — it must not be counted as both. So title is used as the description only when it was NOT already consumed as the element's name.

Class Method Summary collapse

Class Method Details

.compute(element) ⇒ Object

The accessible description string ("" when none).



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dommy/internal/accessible_description.rb', line 20

def compute(element)
  return "" unless element.respond_to?(:__dommy_backend_node__)

  described = AccessibleName.referenced_names(element, "aria-describedby")
  return described.strip if described

  attr = element.get_attribute("aria-description").to_s
  return attr.strip unless attr.strip.empty?

  title = element.get_attribute("title").to_s.strip
  return "" if title.empty?
  # title already serves as the accessible name — don't double-count it.
  return "" if AccessibleName.compute(element) == title

  title
end