Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Check parentElement to skip shadowRoots (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
valdrinkoshi authored May 30, 2017
1 parent 4246af1 commit 002f84f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
7 changes: 3 additions & 4 deletions paper-dialog-scrollable.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ <h4>Sub-header</h4>
},

_ensureTarget: function () {
// read parentNode on attached because if dynamically created,
// parentNode will be null on creation.
this.dialogElement = this.dialogElement || Polymer.dom(this).parentNode;
// Check if parent implements paper-dialog-behavior. If not, fit scrollTarget to host.
// Read parentElement instead of parentNode in order to skip shadowRoots.
this.dialogElement = this.dialogElement || this.parentElement;
// Check if dialog implements paper-dialog-behavior. If not, fit scrollTarget to host.
if (this.dialogElement && this.dialogElement.behaviors &&
this.dialogElement.behaviors.indexOf(Polymer.PaperDialogBehaviorImpl) >= 0) {
this.dialogElement.sizingTarget = this.scrollTarget;
Expand Down
27 changes: 27 additions & 0 deletions test/paper-dialog-scrollable.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<link rel="import" href="../paper-dialog-scrollable.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../paper-dialog/paper-dialog.html">
<link rel="import" href="test-dialog.html">

<custom-style><style is="custom-style">
.fixed-height {
Expand Down Expand Up @@ -100,6 +101,15 @@ <h2>Dialog</h2>
</template>
</test-fixture>

<test-fixture id="shadow">
<template>
<test-dialog opened>
<h2 slot="title">Dialog</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</test-dialog>
</template>
</test-fixture>

<script>

function runAfterScroll(node, scrollTop, callback) {
Expand Down Expand Up @@ -232,6 +242,23 @@ <h2>Dialog</h2>
}, 10);
});

test('correctly sized (container = test-dialog[opened])', function(done) {
var dialog = fixture('shadow');
var scrollable = dialog.$.scrollable;
// Wait for dialog to be opened and styles applied.
dialog.addEventListener('iron-overlay-opened', function() {
var dRect = dialog.getBoundingClientRect();
var sRect = scrollable.getBoundingClientRect();
var stRect = scrollable.scrollTarget.getBoundingClientRect();
assert.equal(sRect.width, dRect.width, 'scrollable width ok');
assert.isAbove(sRect.height, 0, 'scrollable height bigger than 0');
assert.isBelow(sRect.height, dRect.height, 'scrollable height contained in dialog height');
assert.equal(stRect.width, sRect.width, 'scrollTarget width ok');
assert.equal(stRect.height, sRect.height, 'scrollTarget height ok');
done();
});
});

});

</script>
Expand Down
25 changes: 25 additions & 0 deletions test/test-dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../../paper-dialog-behavior/paper-dialog-behavior.html">

<dom-module id="test-dialog">
<template>
<slot name="title"></slot>
<paper-dialog-scrollable id="scrollable">
<slot></slot>
</paper-dialog-scrollable>
</template>
<script>
Polymer({
is: 'test-dialog',
behaviors: [Polymer.PaperDialogBehavior]
});
</script>
</dom-module>

0 comments on commit 002f84f

Please sign in to comment.