Skip to content

Commit f3edb8c

Browse files
committed
Merge branch 'US206196--modal-web-component' of https://github.com/patternfly/patternfly-elements into US206196--modal-web-component
2 parents e7ad62d + d752bdc commit f3edb8c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

elements/pfe-modal/demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
56
<title>PatternFly Element | pfe-modal Demo</title>
67

78
<noscript>

elements/pfe-modal/src/pfe-modal.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ class PfeModal extends PFElement {
6464
constructor() {
6565
super(PfeModal, { type: PfeModal.PfeType });
6666

67-
this.open = false;
6867
this.header_id = this.randomId;
6968

69+
this.open = false;
70+
7071
this._keydownHandler = this._keydownHandler.bind(this);
7172
this._toggleModal = this._toggleModal.bind(this);
7273

@@ -179,6 +180,8 @@ class PfeModal extends PFElement {
179180
this._modalWindow.removeAttribute("hidden");
180181
this._overlay.removeAttribute("hidden");
181182
this._outer.removeAttribute("hidden");
183+
// This prevents background scroll
184+
document.body.style.overflow = "hidden";
182185
// Set the focus to the container
183186
this._modalWindow.focus();
184187
} else {
@@ -187,6 +190,8 @@ class PfeModal extends PFElement {
187190
this._modalWindow.setAttribute("hidden", true);
188191
this._overlay.setAttribute("hidden", true);
189192
this._outer.setAttribute("hidden", true);
193+
// Return scrollability
194+
document.body.style.overflow = "auto";
190195
// Move focus back to the trigger element
191196
this.trigger.focus();
192197
}

elements/pfelement/src/pfelement.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class PFElement extends HTMLElement {
3030
static get version() {
3131
return "{{version}}";
3232
}
33+
34+
static get randomId() {
35+
return Math.random().toString(36).substr(2, 9);
36+
}
3337

3438
get version() {
3539
return this._pfeClass.version;
@@ -38,10 +42,6 @@ class PFElement extends HTMLElement {
3842
get pfeType() {
3943
return this.getAttribute(`${prefix}type`);
4044
}
41-
42-
get randomId() {
43-
return Math.random().toString(36).substr(2, 9);
44-
}
4545

4646
set pfeType(value) {
4747
this.setAttribute(`${prefix}type`, value);

0 commit comments

Comments
 (0)