aom icon indicating copy to clipboard operation
aom copied to clipboard

Reference to DOM Node

Open CountOrlok opened this issue 7 years ago • 2 comments

An AccessibleNode should contain a reference to the Node it is associated with.

function doSomethingWith (accessibleNode) {
  const domNode = accessibleNode.associatedNode;
}

const element = document.getElementById('name');
doSomethingWith(element.accessibleNode); // or accessibleElement

I don't know what name the property should have, though. associatedNode, DOMNode or simply node?

interface AccessibleNode {
  readonly attribute Node? node;
}

Anyway, it should be defined as a Nullable Type, since Virtual Nodes would not have a corresponding DOM node.

CountOrlok avatar Mar 19 '17 13:03 CountOrlok

Clearly it must have one internally. What's the use case for making it public?

I think it might make sense to add this in Phase 3, as it'd be a way to distinguish between DOM and Virtual accessible nodes.

minorninth avatar Mar 20 '17 06:03 minorninth

Obviously there is no technical need for making the reference public, but I think it should be included for convenience and for consistency with other APIs.

As it is now, if you directly reference an accessible node, you lose context. So, if you want to delegate some work with accessible nodes and you need a reference to the associated elements at one point, you can't just pass those accessible nodes around. That's not a common use case and of cause you can easily work around this, but I think it'd be nice if you didn't have to provide the reference by yourself.

I think it would also be pretty unusual to have an object associated with another object in a comparable way without providing a public reference, if we look at other Web APIs. So, for example, consider the Shadow DOM:

interface Element : Node {
  readonly attribute ShadowRoot? shadowRoot;
};

The Element interface provides a reference to the ShadowRoot, if there is one.

interface ShadowRoot : DocumentFragment {
  readonly attribute Element host;
};

The ShadowRoot provides a reference to the Element which is its host.

CountOrlok avatar Mar 20 '17 15:03 CountOrlok