Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Shadow DOM #5585

Merged
merged 4 commits into from
Jul 7, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[BUG] Shadow DOM & Root: Failed to execute 'getComputedStyle' on 'Win…
…dow'
reda-alaoui committed Jun 21, 2018
commit e14c77198a622ff4a09a69ffddb8d32aeb9598df
9 changes: 9 additions & 0 deletions src/core/core.helpers.js
Original file line number Diff line number Diff line change
@@ -451,6 +451,9 @@ module.exports = function() {
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
var view = document.defaultView;
var parentNode = domNode.parentNode;
if (parentNode && parentNode.host) {
parentNode = parentNode.host;
}
var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
var hasCNode = isConstrainedValue(constrainedNode);
@@ -486,6 +489,9 @@ module.exports = function() {
if (!container) {
return domNode.clientWidth;
}
if (container.host) {
container = container.host;
}

var clientWidth = container.clientWidth;
var paddingLeft = helpers._calculatePadding(container, 'padding-left', clientWidth);
@@ -500,6 +506,9 @@ module.exports = function() {
if (!container) {
return domNode.clientHeight;
}
if (container.host) {
container = container.host;
}

var clientHeight = container.clientHeight;
var paddingTop = helpers._calculatePadding(container, 'padding-top', clientHeight);
25 changes: 25 additions & 0 deletions test/specs/core.helpers.tests.js
Original file line number Diff line number Diff line change
@@ -568,6 +568,31 @@ describe('Core helper tests', function() {
document.body.removeChild(div);
});

it ('should get the maximum width and height for a node in a ShadowRoot', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
div.style.width = '200px';
div.style.height = '300px';

document.body.appendChild(div);

if (!div.attachShadow) {
// Shadow DOM is not natively supported
return;
}

var shadow = div.attachShadow({mode: 'closed'});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we reach this point when tests are executed by our CI / Travis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in Chrome, not in Firefox.


// Create the div we want to get the max size for
var innerDiv = document.createElement('div');
shadow.appendChild(innerDiv);

expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
expect(helpers.getMaximumHeight(innerDiv)).toBe(300);

document.body.removeChild(div);
});

it ('should get the maximum width of a node that has a max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');