Skip to content

Commit

Permalink
Fixes #46: Polymer.dom(..).activeElement gets _activeElement (Sha…
Browse files Browse the repository at this point in the history
…dyDOM) if available.
  • Loading branch information
bicknellr committed Nov 3, 2016
1 parent 009edc5 commit 66af285
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/polymer.dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
return list;
}

get activeElement() {
let node = this.node;
return node._activeElement !== undefined ? node._activeElement : node.activeElement;
}
}

function forwardMethods(proto, methods) {
Expand Down Expand Up @@ -293,7 +297,6 @@
]);

forwardReadOnlyProperties(DomApi.prototype, [
'activeElement',
'parentNode', 'firstChild', 'lastChild',
'nextSibling', 'previousSibling', 'firstElementChild',
'lastElementChild', 'nextElementSibling', 'previousElementSibling',
Expand Down
29 changes: 29 additions & 0 deletions test/unit/polymer-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@
</script>
</dom-module>

<dom-module id="x-focusable-in-shadow">
<template>
<input id="focusable"></input>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-focusable-in-shadow'
});
});
</script>
</dom-module>

<test-fixture id="scoped">
<template>
<x-event-scoped></x-event-scoped>
Expand All @@ -71,6 +84,12 @@
</template>
</test-fixture>

<test-fixture id="focusableInShadow">
<template>
<x-focusable-in-shadow></x-focusable-in-shadow>
</template>
</test-fixture>

<script>

suite('exteded dom api', function() {
Expand Down Expand Up @@ -157,6 +176,16 @@

});

suite('activeElement getter', function() {
test('Retrieves `_activeElement` (ShadyDOM) or `activeElement`.', function() {
var focusableInShadow = fixture('focusableInShadow');
focusableInShadow.$.focusable.focus();
var rootNode = focusableInShadow.getRootNode();
assert.equal(Polymer.dom(rootNode).activeElement, focusableInShadow);
assert.equal(Polymer.dom(focusableInShadow.shadowRoot).activeElement, focusableInShadow.$.focusable);
});
});

</script>

</body>
Expand Down

0 comments on commit 66af285

Please sign in to comment.