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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/core/core.helpers.js
Expand Up @@ -450,7 +450,7 @@ module.exports = function() {
// @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
var view = document.defaultView;
var parentNode = domNode.parentNode;
var parentNode = helpers._getParentNode(domNode);
var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
var hasCNode = isConstrainedValue(constrainedNode);
Expand Down Expand Up @@ -481,8 +481,18 @@ module.exports = function() {

return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10);
};
/**
* @private
*/
helpers._getParentNode = function(domNode) {
var parent = domNode.parentNode;
if (parent && parent.host) {
parent = parent.host;
}
return parent;
};
helpers.getMaximumWidth = function(domNode) {
var container = domNode.parentNode;
var container = helpers._getParentNode(domNode);
if (!container) {
return domNode.clientWidth;
}
Expand All @@ -496,7 +506,7 @@ module.exports = function() {
return isNaN(cw) ? w : Math.min(w, cw);
};
helpers.getMaximumHeight = function(domNode) {
var container = domNode.parentNode;
var container = helpers._getParentNode(domNode);
if (!container) {
return domNode.clientHeight;
}
Expand Down
25 changes: 25 additions & 0 deletions test/specs/core.helpers.tests.js
Expand Up @@ -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');
Expand Down