Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
fix: fixed broken behaviour for style attribute (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pferretti committed Aug 8, 2017
1 parent 38b4fde commit c72a24b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist/ikonograph.js

Large diffs are not rendered by default.

43 changes: 19 additions & 24 deletions src/ikonograph.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,27 @@ class IkonographIcon extends HTMLElement {
this.attributeChangeManager[attributeName](newValue);
}

_svgStyleString(size, color, hasShadowDOM) {
// we need to know if there's support for :host or not
const host = hasShadowDOM ? ':host' : 'ikn-icon';
_svgStyleString(size, color) {
size = size || DEFAULT_HOST_SIZE;
color = color || DEFAULT_COLOR;

const commonStyle = `
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
contain: content;
pointer-events: auto;
width: ${size};
height: ${size};
`;

return `
${host} {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
contain: content;
pointer-events: auto;
width: ${size};
height: ${size};
:host {
${commonStyle}
}
ikn-icon {
${commonStyle}
}
svg {
Expand Down Expand Up @@ -118,21 +125,9 @@ class IkonographIcon extends HTMLElement {
this._removeChild('style');
const styleElement = document.createElement('style');
this.shadow.appendChild(styleElement);
styleElement.innerHTML = this._svgStyleString(size, color, true);

// right next the style apply, we need to check if the style is really
// applied to our element. This is a sort of feature detection
// to check if a browser support :host
const styleApplied = this._isStyleApplied(size);
if (!styleApplied) {
styleElement.innerHTML = this._svgStyleString(size, color, false);
}
styleElement.innerHTML = this._svgStyleString(size, color);
}

_isStyleApplied(size) {
const computedStyle = window.getComputedStyle(this).width || DEFAULT_HOST_SIZE
return window.getComputedStyle(this).width === size;
}
}

customElements.define('ikn-icon', IkonographIcon);

0 comments on commit c72a24b

Please sign in to comment.