Skip to content

ShadowRoot ​

class ShadowRoot extends DocumentFragment implements DocumentOrShadowRoot

Annotations: @SupportedBrowser.new(SupportedBrowser.CHROME, '26'), @Native.new("ShadowRoot")

Inheritance

Object → EventTarget → Node → DocumentFragment → ShadowRoot

Implemented types

Properties ​

activeElement no setter override ​

Element? get activeElement
Implementation
dart
Element? get activeElement native;

deprecated applyAuthorStyles read / write ​

bool get applyAuthorStyles

DEPRECATED

Implementation
dart
@deprecated
bool get applyAuthorStyles {
  _shadowRootDeprecationReport();
  // Default value from when it was specified.
  return false;
}

@deprecated
set applyAuthorStyles(bool value) {
  _shadowRootDeprecationReport();
}

baseUri no setter inherited ​

String? get baseUri

Inherited from Node.

Implementation
dart
@JSName('baseURI')
String? get baseUri native;

childNodes no setter inherited ​

List<Node> get childNodes

A list of this node's children.

Other resources ​

Inherited from Node.

Implementation
dart
@Returns('NodeList')
@Creates('NodeList')
List<Node> get childNodes native;

children read / write inherited ​

List<Element> get children

Inherited from DocumentFragment.

Implementation
dart
List<Element> get children {
  if (_docChildren == null) {
    _docChildren = new FilteredElementList(this);
  }
  return _docChildren!;
}

set children(List<Element> value) {
  &#47;&#47; Copy list first since we don't want liveness during iteration.
  var copy = value.toList();
  var children = this.children;
  children.clear();
  children.addAll(copy);
}

delegatesFocus no setter ​

bool? get delegatesFocus
Implementation
dart
bool? get delegatesFocus native;

firstChild no setter inherited ​

Node? get firstChild

The first child of this node.

Other resources ​

Inherited from Node.

Implementation
dart
Node? get firstChild native;

fullscreenElement no setter override ​

Element? get fullscreenElement
Implementation
dart
Element? get fullscreenElement native;

hashCode no setter inherited ​

int get hashCode

Inherited from Interceptor.

Implementation
dart
int get hashCode => Primitives.objectHashCode(this);

host no setter ​

Element? get host
Implementation
dart
Element? get host native;

innerHtml read / write override ​

String? get innerHtml
Implementation
dart
@JSName('innerHTML')
String? get innerHtml native;

@JSName('innerHTML')
set innerHtml(String? value) native;

isConnected no setter inherited ​

bool? get isConnected

Inherited from Node.

Implementation
dart
bool? get isConnected native;

lastChild no setter inherited ​

Node? get lastChild

The last child of this node.

Other resources ​

Inherited from Node.

Implementation
dart
Node? get lastChild native;

mode no setter ​

String? get mode
Implementation
dart
String? get mode native;

nextNode no setter inherited ​

Node? get nextNode

The next sibling node.

Other resources ​

Inherited from Node.

Implementation
dart
@JSName('nextSibling')
&#47;**
 * The next sibling node.
 *
 * ## Other resources
 *
 * * [Node.nextSibling](https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;API&#47;Node.nextSibling)
 *   from MDN.
 *&#47;
Node? get nextNode native;

nodeName no setter inherited ​

String? get nodeName

The name of this node.

This varies by this node's nodeType.

Other resources ​

Inherited from Node.

Implementation
dart
String? get nodeName native;

nodes read / write inherited ​

List<Node> get nodes

A modifiable list of this node's children.

Inherited from Node.

Implementation
dart
List<Node> get nodes {
  return new _ChildNodeListLazy(this);
}

set nodes(Iterable<Node> value) {
  &#47;&#47; Copy list first since we don't want liveness during iteration.
  &#47;&#47; TODO(jacobr): there is a better way to do this.
  var copy = value.toList();
  text = '';
  for (Node node in copy) {
    append(node);
  }
}

nodeType no setter inherited ​

int get nodeType

The type of node.

This value is one of:

Other resources ​

Inherited from Node.

Implementation
dart
int get nodeType native;

nodeValue no setter inherited ​

String? get nodeValue

The value of this node.

This varies by this type's nodeType.

Other resources ​

Inherited from Node.

Implementation
dart
String? get nodeValue native;

olderShadowRoot no setter ​

ShadowRoot? get olderShadowRoot
Implementation
dart
ShadowRoot? get olderShadowRoot native;

on no setter inherited ​

Events get on

This is an ease-of-use accessor for event streams which should only be used when an explicit accessor is not available.

Inherited from EventTarget.

Implementation
dart
Events get on => new Events(this);

ownerDocument no setter inherited ​

Document? get ownerDocument

The document this node belongs to.

Returns null if this node does not belong to any document.

Other resources ​

Inherited from Node.

Implementation
dart
Document? get ownerDocument native;

parent no setter inherited ​

Element? get parent

The parent element of this node.

Returns null if this node either does not have a parent or its parent is not an element.

Other resources ​

Inherited from Node.

Implementation
dart
@JSName('parentElement')
&#47;**
 * The parent element of this node.
 *
 * Returns null if this node either does not have a parent or its parent is
 * not an element.
 *
 * ## Other resources
 *
 * * [Node.parentElement](https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;API&#47;Node.parentElement)
 *   from W3C.
 *&#47;
Element? get parent native;

parentNode no setter inherited ​

Node? get parentNode

The parent node of this node.

Other resources ​

Inherited from Node.

Implementation
dart
Node? get parentNode native;

pointerLockElement no setter override ​

Element? get pointerLockElement
Implementation
dart
Element? get pointerLockElement native;

previousNode no setter inherited ​

Node? get previousNode

The previous sibling node.

Other resources ​

Inherited from Node.

Implementation
dart
@JSName('previousSibling')
&#47;**
 * The previous sibling node.
 *
 * ## Other resources
 *
 * * [Node.previousSibling](https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;API&#47;Node.previousSibling)
 *   from MDN.
 *&#47;
Node? get previousNode native;

deprecated resetStyleInheritance read / write ​

bool get resetStyleInheritance

DEPRECATED

Implementation
dart
@deprecated
bool get resetStyleInheritance {
  _shadowRootDeprecationReport();
  &#47;&#47; Default value from when it was specified.
  return false;
}

@deprecated
set resetStyleInheritance(bool value) {
  _shadowRootDeprecationReport();
}

runtimeType no setter inherited ​

Type get runtimeType

Inherited from Interceptor.

Implementation
dart
Type get runtimeType =>
    getRuntimeTypeOfInterceptorNotArray(getInterceptor(this), this);

styleSheets no setter override ​

List<StyleSheet>? get styleSheets
Implementation
dart
@Returns('_StyleSheetList')
@Creates('_StyleSheetList')
List<StyleSheet>? get styleSheets native;

text read / write inherited ​

String? get text

All text within this node and its descendants.

Other resources ​

Inherited from Node.

Implementation
dart
@JSName('textContent')
&#47;**
 * All text within this node and its descendants.
 *
 * ## Other resources
 *
 * * [Node.textContent](https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;API&#47;Node.textContent)
 *   from MDN.
 *&#47;
String? get text native;

@JSName('textContent')
set text(String? value) native;

Methods ​

addEventListener() inherited ​

void addEventListener(
  String type,
  (dynamic Function(Event event))? listener, [
  bool? useCapture,
])

Inherited from EventTarget.

Implementation
dart
void addEventListener(
  String type,
  EventListener? listener, [
  bool? useCapture,
]) {
  &#47;&#47; TODO(leafp): This check is avoid a bug in our dispatch code when
  &#47;&#47; listener is null.  The browser treats this call as a no-op in this
  &#47;&#47; case, so it's fine to short-circuit it, but we should not have to.
  if (listener != null) {
    _addEventListener(type, listener, useCapture);
  }
}

append() inherited ​

Node append(Node node)

Adds a node to the end of the child nodes list of this node.

If the node already exists in this document, it will be removed from its current parent node, then added to this node.

This method is more efficient than nodes.add, and is the preferred way of appending a child node.

Inherited from Node.

Implementation
dart
@JSName('appendChild')
&#47;**
 * Adds a node to the end of the child [nodes] list of this node.
 *
 * If the node already exists in this document, it will be removed from its
 * current parent node, then added to this node.
 *
 * This method is more efficient than `nodes.add`, and is the preferred
 * way of appending a child node.
 *&#47;
Node append(Node node) native;

appendHtml() inherited ​

void appendHtml(
  String text, {
  NodeValidator? validator,
  NodeTreeSanitizer? treeSanitizer,
})

Parses the specified text as HTML and adds the resulting node after the last child of this document fragment.

Inherited from DocumentFragment.

Implementation
dart
void appendHtml(
  String text, {
  NodeValidator? validator,
  NodeTreeSanitizer? treeSanitizer,
}) {
  this.append(
    new DocumentFragment.html(
      text,
      validator: validator,
      treeSanitizer: treeSanitizer,
    ),
  );
}

appendText() inherited ​

void appendText(String text)

Adds the specified text as a text node after the last child of this document fragment.

Inherited from DocumentFragment.

Implementation
dart
void appendText(String text) {
  this.append(new Text(text));
}

clone() inherited ​

Node clone(bool? deep)

Returns a copy of this node.

If deep is true, then all of this node's children and descendants are copied as well. If deep is false, then only this node is copied.

Other resources ​

Inherited from Node.

Implementation
dart
@JSName('cloneNode')
&#47;**
 * Returns a copy of this node.
 *
 * If [deep] is `true`, then all of this node's children and descendants are
 * copied as well. If [deep] is `false`, then only this node is copied.
 *
 * ## Other resources
 *
 * * [Node.cloneNode](https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;API&#47;Node.cloneNode)
 *   from MDN.
 *&#47;
Node clone(bool? deep) native;

contains() inherited ​

bool contains(Node? other)

Returns true if this node contains the specified node.

Other resources ​

Inherited from Node.

Implementation
dart
bool contains(Node? other) native;

dispatchEvent() inherited ​

bool dispatchEvent(Event event)

Inherited from EventTarget.

Implementation
dart
bool dispatchEvent(Event event) native;

elementFromPoint() override ​

Element? elementFromPoint(int x, int y)
Implementation
dart
Element? elementFromPoint(int x, int y) native;

elementsFromPoint() override ​

List<Element> elementsFromPoint(int x, int y)
Implementation
dart
List<Element> elementsFromPoint(int x, int y) native;

getElementById() inherited ​

Element? getElementById(String elementId)

Inherited from DocumentFragment.

Implementation
dart
Element? getElementById(String elementId) native;

getRootNode() inherited ​

Node getRootNode([Map<dynamic, dynamic>? options])

Inherited from Node.

Implementation
dart
Node getRootNode([Map? options]) {
  if (options != null) {
    var options_1 = convertDartToNative_Dictionary(options);
    return _getRootNode_1(options_1);
  }
  return _getRootNode_2();
}

getSelection() override ​

Selection? getSelection()
Implementation
dart
Selection? getSelection() native;

hasChildNodes() inherited ​

bool hasChildNodes()

Returns true if this node has any children.

Other resources ​

Inherited from Node.

Implementation
dart
bool hasChildNodes() native;

insertAllBefore() inherited ​

void insertAllBefore(Iterable<Node> newNodes, Node child)

Inserts all of the nodes into this node directly before child.

See also:

Inherited from Node.

Implementation
dart
void insertAllBefore(Iterable<Node> newNodes, Node child) {
  if (newNodes is _ChildNodeListLazy) {
    _ChildNodeListLazy otherList = newNodes;
    if (identical(otherList._this, this)) {
      throw new ArgumentError(newNodes);
    }

    &#47;&#47; Optimized route for copying between nodes.
    for (var i = 0, len = otherList.length; i < len; ++i) {
      this.insertBefore(otherList._this.firstChild!, child);
    }
  } else {
    for (var node in newNodes) {
      this.insertBefore(node, child);
    }
  }
}

insertBefore() inherited ​

Node insertBefore(Node node, Node? child)

Inserts the given node into this node directly before child. If child is null, then the given node is inserted at the end of this node's child nodes.

Other resources ​

Inherited from Node.

Implementation
dart
Node insertBefore(Node node, Node? child) native;

noSuchMethod() inherited ​

dynamic noSuchMethod(Invocation invocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Inherited from Interceptor.

Implementation
dart
dynamic noSuchMethod(Invocation invocation) {
  throw NoSuchMethodError.withInvocation(this, invocation);
}

querySelector() inherited ​

Element? querySelector(String selectors)

Finds the first descendant element of this document fragment that matches the specified group of selectors.

selectors should be a string using CSS selector syntax.

dart
var element1 = fragment.querySelector('.className');
var element2 = fragment.querySelector('#id');

For details about CSS selector syntax, see the CSS selector specification.

Inherited from DocumentFragment.

Implementation
dart
Element? querySelector(String selectors) native;

querySelectorAll() inherited ​

ElementList<T> querySelectorAll<T extends Element>(String selectors)

Finds all descendant elements of this document fragment that match the specified group of selectors.

selectors should be a string using CSS selector syntax.

dart
var items = document.querySelectorAll('.itemClassName');

For details about CSS selector syntax, see the CSS selector specification.

Inherited from DocumentFragment.

Implementation
dart
ElementList<T> querySelectorAll<T extends Element>(String selectors) =>
    new _FrozenElementList<T>._wrap(_querySelectorAll(selectors));

remove() inherited ​

void remove()

Removes this node from the DOM.

Inherited from Node.

Implementation
dart
void remove() {
  &#47;&#47; TODO(jacobr): should we throw an exception if parent is already null?
  &#47;&#47; TODO(vsm): Use the native remove when available.
  if (this.parentNode != null) {
    final Node parent = this.parentNode!;
    parent._removeChild(this);
  }
}

removeEventListener() inherited ​

void removeEventListener(
  String type,
  (dynamic Function(Event event))? listener, [
  bool? useCapture,
])

Inherited from EventTarget.

Implementation
dart
void removeEventListener(
  String type,
  EventListener? listener, [
  bool? useCapture,
]) {
  &#47;&#47; TODO(leafp): This check is avoid a bug in our dispatch code when
  &#47;&#47; listener is null.  The browser treats this call as a no-op in this
  &#47;&#47; case, so it's fine to short-circuit it, but we should not have to.
  if (listener != null) {
    _removeEventListener(type, listener, useCapture);
  }
}

replaceWith() inherited ​

Node replaceWith(Node otherNode)

Replaces this node with another node.

Inherited from Node.

Implementation
dart
Node replaceWith(Node otherNode) {
  try {
    final Node parent = this.parentNode!;
    parent._replaceChild(otherNode, this);
  } catch (e) {}
  return this;
}

setInnerHtml() inherited ​

void setInnerHtml(
  String? html, {
  NodeValidator? validator,
  NodeTreeSanitizer? treeSanitizer,
})

Inherited from DocumentFragment.

Implementation
dart
void setInnerHtml(
  String? html, {
  NodeValidator? validator,
  NodeTreeSanitizer? treeSanitizer,
}) {
  this.nodes.clear();
  append(
    document.body!.createFragment(
      html,
      validator: validator,
      treeSanitizer: treeSanitizer,
    ),
  );
}

toString() inherited ​

String toString()

Print out a String representation of this Node.

Inherited from Node.

Implementation
dart
String toString() {
  String? value = nodeValue; &#47;&#47; Fetch DOM Node property once.
  return value == null ? super.toString() : value;
}

Operators ​

operator ==() inherited ​

bool operator ==(Object other)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Inherited from Interceptor.

Implementation
dart
bool operator ==(Object other) => identical(this, other);

Static Properties ​

supported no setter ​

bool get supported
Implementation
dart
static bool get supported => JS(
  'bool',
  '!!(Element.prototype.createShadowRoot||'
      'Element.prototype.webkitCreateShadowRoot)',
);