ally.event.shadowFocus

September 28, 2016 ยท View on GitHub

Observes focus changes within ShadowDOMs and emits shadow-focus CustomEvents.

Description

Usage

document.addEventListener('shadow-focus', function(event) {
  // event.detail.elements: complete focus ancestry (array of nodes)
  // event.detail.active: the actually focused element within the ShadowDOM
  // event.detail.hosts: the shadow host ancestry of the active element
}, false);

// start emitting shadow-focus
var handle = ally.event.shadowFocus();
// stop emitting shadow-focus
handle.disengage();

Arguments

Returns

A <global-service> interface, providing the handle.disengage() method to stop the service.

Throws

Event data

The event.detail property provides the following data:

NameTypeDescription
event.detail.activeHTMLElementThe actually focused element within the ShadowDOM.
event.detail.elementsarray of HTMLElementThe complete focus ancestry
event.detail.hostsarray of HTMLElementThe ShadowHost ancestry of the active element.

Examples

Changes

  • Since v1.1.1 the module does not access document.body at load time anymore.

Notes

Contributing