Skip to content

Commit 0d568e8

Browse files
author
Ryan A. Johnson
committed
fix(ShadowDOM): fix broken elements
An update in #216 removed the `HXElement(tagName, template)` constructor implementation, which broke every element that relied on it. This commit fixes that by updating all class implementations to the new API format, using `static get template`. * Update visreg baselines * Update classes to use new APIs
1 parent 4ecfe92 commit 0d568e8

18 files changed

+96
-112
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<hx-icon type="exclamation-circle" id="icon"></hx-icon>
2+
<slot></slot>
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { HXElement } from './HXElement';
22
import shadowStyles from './HXErrorElement.less';
3-
4-
const tagName = 'hx-error';
5-
const template = document.createElement('template');
6-
7-
template.innerHTML = `
8-
<style>${shadowStyles}</style>
9-
<hx-icon type="exclamation-circle"></hx-icon>
10-
<slot></slot>
11-
`;
3+
import shadowMarkup from './HXErrorElement.html';
124

135
export class HXErrorElement extends HXElement {
146
static get is () {
15-
return tagName;
7+
return 'hx-error';
168
}
179

18-
constructor () {
19-
super(tagName, template);
10+
static get template () {
11+
return `<style>${shadowStyles}</style>${shadowMarkup}`;
2012
}
2113
}//HXErrorElement
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
@import './HXElement';
22
@import 'elements/hx-icon';
3+
4+
#icon {
5+
margin-right: 0.25rem;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div id="container">
2+
<button type="button" id="close">
3+
<hx-icon type="times"></hx-icon>
4+
</button>
5+
<slot></slot>
6+
</div>

src/helix-ui/elements/HXModalElement.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
import { HXElement } from './HXElement';
22
import { KEYS } from '../util';
3+
import shadowMarkup from './HXModalElement.html';
34
import shadowStyles from './HXModalElement.less';
45

5-
const tagName = 'hx-modal';
6-
const template = document.createElement('template');
7-
8-
template.innerHTML = `
9-
<style>${shadowStyles}</style>
10-
<div id="container">
11-
<button type="button" id="close">
12-
<hx-icon type="times"></hx-icon>
13-
</button>
14-
<slot></slot>
15-
</div>
16-
`;
17-
186
export class HXModalElement extends HXElement {
197
static get is () {
20-
return tagName;
8+
return 'hx-modal';
9+
}
10+
11+
static get template () {
12+
return `<style>${shadowStyles}</style>${shadowMarkup}`;
2113
}
2214

2315
static get observedAttributes () {
2416
return [ 'open' ];
2517
}
2618

2719
constructor () {
28-
super(tagName, template);
20+
super();
2921
this._close = this._close.bind(this);
3022
this._keyUp = this._keyUp.bind(this);
3123
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="position-arrow">
2+
<div id="container">
3+
<slot></slot>
4+
</div>
5+
</div>

src/helix-ui/elements/HXPopoverElement.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
import { HXElement } from './HXElement';
22
import { getPositionWithArrow } from '../util';
33
import debounce from 'lodash/debounce';
4+
import shadowMarkup from './HXPopoverElement.html';
45
import shadowStyles from './HXPopoverElement.less';
56

6-
const tagName = 'hx-popover';
7-
const template = document.createElement('template');
8-
9-
template.innerHTML = `
10-
<style>${shadowStyles}</style>
11-
<div class="position-arrow">
12-
<div id="container">
13-
<slot></slot>
14-
</div>
15-
</div>
16-
`;
17-
187
export class HXPopoverElement extends HXElement {
198
static get is () {
20-
return tagName;
9+
return 'hx-popover';
10+
}
11+
12+
static get template () {
13+
return `<style>${shadowStyles}</style>${shadowMarkup}`;
2114
}
2215

2316
static get observedAttributes () {
2417
return [ 'open' ];
2518
}
2619

2720
constructor () {
28-
super(tagName, template);
21+
super();
2922
this._toggle = this._toggle.bind(this);
3023
this._setPosition = this._setPosition.bind(this);
3124
this._closeOnBackdropClick = this._closeOnBackdropClick.bind(this);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="fill"></div>

src/helix-ui/elements/HXProgressElement.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import { HXElement } from './HXElement';
2+
import shadowMarkup from './HXProgressElement.html';
3+
import shadowStyles from './HXProgressElement.less';
24

35
const MIN = 0;
46
const MAX = 100;
57

6-
const tagName = 'hx-progress';
7-
const template = document.createElement('template');
8-
template.innerHTML = `
9-
<style>
10-
#fill {
11-
background-color: currentColor;
12-
box-sizing: border-box;
13-
height: 100%;
14-
width: 0%;
15-
}
16-
</style>
17-
<div id="fill"></div>
18-
`;
19-
208
/**
219
* @private
2210
* @param {*} val - Value to coerce into an Integer
@@ -40,11 +28,11 @@ function _parseValue (val) {
4028
*/
4129
export class HXProgressElement extends HXElement {
4230
static get is () {
43-
return tagName;
31+
return 'hx-progress';
4432
}
4533

46-
constructor () {
47-
super(tagName, template);
34+
static get template () {
35+
return `<style>${shadowStyles}</style>${shadowMarkup}`;
4836
}
4937

5038
connectedCallback () {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#fill {
2+
background-color: currentColor;
3+
box-sizing: border-box;
4+
height: 100%;
5+
width: 0%;
6+
}

0 commit comments

Comments
 (0)