Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit d8d1953

Browse files
committed
Move build codeinto connectedCallback
1 parent a5ccf5e commit d8d1953

File tree

2 files changed

+47
-46
lines changed

2 files changed

+47
-46
lines changed

dist/index-umd.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,57 +75,59 @@
7575
function DetailsDialogElement() {
7676
_classCallCheck(this, DetailsDialogElement);
7777

78-
var _this = _possibleConstructorReturn(this, (DetailsDialogElement.__proto__ || Object.getPrototypeOf(DetailsDialogElement)).call(this));
79-
80-
_this.createCloseButton();
81-
_this.details = _this.parentElement;
82-
_this.setAttribute('role', 'dialog');
83-
84-
var keyDownHelpers = _this.keyDownHelpers.bind(_this);
85-
var captureDismissal = _this.captureDismissal.bind(_this);
86-
87-
_this.details.addEventListener('toggle', function () {
88-
if (this.details.open) {
89-
this.autofocus();
90-
this.details.addEventListener('keydown', keyDownHelpers);
91-
this.addEventListener('click', captureDismissal);
92-
} else {
93-
var _iteratorNormalCompletion = true;
94-
var _didIteratorError = false;
95-
var _iteratorError = undefined;
96-
97-
try {
98-
for (var _iterator = this.querySelectorAll('form')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
99-
var form = _step.value;
100-
101-
form.reset();
102-
}
103-
} catch (err) {
104-
_didIteratorError = true;
105-
_iteratorError = err;
106-
} finally {
78+
return _possibleConstructorReturn(this, (DetailsDialogElement.__proto__ || Object.getPrototypeOf(DetailsDialogElement)).apply(this, arguments));
79+
}
80+
81+
_createClass(DetailsDialogElement, [{
82+
key: 'connectedCallback',
83+
value: function connectedCallback() {
84+
this.createCloseButton();
85+
this.details = this.parentElement;
86+
this.setAttribute('role', 'dialog');
87+
88+
var keyDownHelpers = this.keyDownHelpers.bind(this);
89+
var captureDismissal = this.captureDismissal.bind(this);
90+
91+
this.details.addEventListener('toggle', function () {
92+
if (this.details.open) {
93+
this.autofocus();
94+
this.details.addEventListener('keydown', keyDownHelpers);
95+
this.addEventListener('click', captureDismissal);
96+
} else {
97+
var _iteratorNormalCompletion = true;
98+
var _didIteratorError = false;
99+
var _iteratorError = undefined;
100+
107101
try {
108-
if (!_iteratorNormalCompletion && _iterator.return) {
109-
_iterator.return();
102+
for (var _iterator = this.querySelectorAll('form')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
103+
var form = _step.value;
104+
105+
form.reset();
110106
}
107+
} catch (err) {
108+
_didIteratorError = true;
109+
_iteratorError = err;
111110
} finally {
112-
if (_didIteratorError) {
113-
throw _iteratorError;
111+
try {
112+
if (!_iteratorNormalCompletion && _iterator.return) {
113+
_iterator.return();
114+
}
115+
} finally {
116+
if (_didIteratorError) {
117+
throw _iteratorError;
118+
}
114119
}
115120
}
116-
}
117121

118-
var summary = this.details.querySelector('summary');
119-
summary.focus();
122+
var summary = this.details.querySelector('summary');
123+
summary.focus();
120124

121-
this.details.removeEventListener('keydown', keyDownHelpers);
122-
this.removeEventListener('click', captureDismissal);
123-
}
124-
}.bind(_this), { capture: true });
125-
return _this;
126-
}
127-
128-
_createClass(DetailsDialogElement, [{
125+
this.details.removeEventListener('keydown', keyDownHelpers);
126+
this.removeEventListener('click', captureDismissal);
127+
}
128+
}.bind(this), { capture: true });
129+
}
130+
}, {
129131
key: 'createCloseButton',
130132
value: function createCloseButton() {
131133
this.closeButton = document.createElement('button');

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class DetailsDialogElement extends HTMLElement {
2-
constructor() {
3-
super()
2+
connectedCallback() {
43
this.createCloseButton()
54
this.details = this.parentElement
65
this.setAttribute('role', 'dialog')

0 commit comments

Comments
 (0)