w3c / accname

Accessible Name and Description Computation
https://w3c.github.io/accname/
60 stars 23 forks source link

Clarifying "text node" definition (step 2G) #212

Open rahimabdi opened 9 months ago

rahimabdi commented 9 months ago

In "4.3.2 Computation steps", Step 2G of the name computation algorithm states:

G. Text Node: Otherwise, if the current node is a Text Node, return its textual contents.

Although a "Node" definition is provided, it's not made explicit what a "text node" is. I would propose adding more documentation, e.g.,:

Other sections that would need updating with linked "node" references:

Further clarification from @cookiecrook and additional context for why this is being recommended in https://github.com/web-platform-tests/wpt/pull/42407#discussion_r1372401204:

These are inherited from XML/DOM terms: most commonly text node versus element node versus comment node. Element nodes can be empty or contain other element, comment, and text nodes, but IIRC text nodes and comment nodes are always leaf nodes.

jnurthen commented 8 months ago

Competing text node definitions:

OrKoN commented 3 weeks ago

I think the spec should also define what the node's textual content is (found this issue by trying to answer the question about how whitespaces should be handled when computing the name).

rahimabdi commented 1 week ago

I would propose using the DOM text interface definition: https://dom.spec.whatwg.org/#interface-text.

@OrKoN from my investigation, the "textual contents" of text nodes (Text interface) is its data; text nodes implement the CharacterData interface which has a data instance property:

Each node inheriting from the CharacterData interface has an associated mutable string called data.

In terms of DOM spec, for text nodes (and also comment nodes), they also inherit from the generic Node interface which has a nodeValue property; it's my understanding that data is the same thing as nodeValue for text nodes.

Depending on the definition's granularity, the textual contents could be the data of the text node although that is less readable than the node's "string value" or simply "text contents" IMO.


July 14 update: Specifically, it looks like the exclusive text node definition should be referenced from the Text interface. An "exclusive text node" is effectively the text contents that is referenced in accname per nodeType.

DOM spec states the definition of "exclusive text node" as:

An exclusive Text node is a Text node that is not a CDATASection node.

OrKoN commented 1 week ago

I think using text node data would not match the current behavior when dealing with whitespaces:

Screenshot 2024-07-12 at 07 42 15

Source: data:text/html,<h2> foo</h2>

OrKoN commented 1 week ago
Screenshot 2024-07-12 at 07 43 37

(nodeValue does appear to be the same in this accessible)

rahimabdi commented 1 week ago

I think using text node data would not match the current behavior when dealing with whitespaces:

I believe trimming whitespace generally from accName/accDescription ((e.g., trailing/leading whitespace) is being tracked here: https://github.com/w3c/accname/issues/95.