Skip to content

Commit 7cbd6fb

Browse files
authored
fix: Deprecated function reference in pfe-modal (#1272)
* fix: Fix patch * fix: Add more info to the changelog * fix: Update modal script
1 parent 4e82f47 commit 7cbd6fb

File tree

3 files changed

+8
-139
lines changed

3 files changed

+8
-139
lines changed

CHANGELOG-1.x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## 1.2.0 ( TBD )
22

33
- [f876664](https://github.com/patternfly/patternfly-elements/commit/f876664655894cbd29d610c20b3bdbde31aaed7a) fix: Sass maps missing from compiled assets
4-
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: Storybook updates required change to knobs add-on import
4+
- [e3fd841](https://github.com/patternfly/patternfly-elements/commit/e3fd8414cf380a45a89f4166ad2f9d9125cf8760) fix: Storybook updates required change to knobs add-on import
5+
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: Remove deprecated method call in pfe-modal, _mapSchemaToSlots
56

67
## 1.1.0 ( 2020-12-22 )
78

docs/content/develop/step-2e.md

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -180,140 +180,6 @@ The events object contains any custom events that this component will fire and f
180180
}
181181
```
182182

183-
## JavaScript
184-
185-
Looking back to our component's JavaScript, we can now add the schema to our web component by adding:
186-
187-
```
188-
get schemaUrl() {
189-
return "pfe-cool-element.json";
190-
}
191-
```
192-
193-
Adding the schema will allow the web component to read in these properties and enforce the schema settings automatically. Inside PFElement, we can see `_mapSchemaToProperties` and `_mapSchemaToSlots` methods. These methods read in the schema and check the web component mark-up for valid or invalid inputs. If an attribute is required but not provided, it will inject that attribute onto the component using the default value from the schema.
194-
195-
Additionally, it will validate the slots being used and add a `has_<slot-name>` attribute to the parent which can be used for styling purposes.
196-
197-
Let's look at our component with the schemaURL added:
198-
199-
200-
```
201-
import PFElement from "../pfelement/dist/pfelement.js";
202-
203-
class PfeCoolElement extends PFElement {
204-
static get tag() {
205-
return "pfe-cool-element";
206-
}
207-
208-
get templateUrl() {
209-
return "pfe-cool-element.html";
210-
}
211-
212-
get styleUrl() {
213-
return "pfe-cool-element.scss";
214-
}
215-
216-
get schemaUrl() {
217-
return "pfe-cool-element.json";
218-
}
219-
220-
static get events() {
221-
return {
222-
select: `${this.tag}:follow`
223-
};
224-
}
225-
226-
follow() {
227-
this.following = !this.following;
228-
229-
this.emitEvent(PfeCoolElement.events.select);
230-
}
231-
232-
set following(value) {
233-
const isFollowing = Boolean(value);
234-
235-
if (isFollowing) {
236-
this.setAttribute("following", "");
237-
} else {
238-
this.removeAttribute("following");
239-
}
240-
}
241-
242-
get following() {
243-
return this.hasAttribute("following");
244-
}
245-
246-
static get observedAttributes() {
247-
return ["following", "photo-url"];
248-
}
249-
250-
constructor() {
251-
super(PfeCoolElement, { type: PfeCoolElement.PfeType });
252-
253-
this.following = false;
254-
255-
this._clickHandler = this._clickHandler.bind(this);
256-
this._keyupHandler = this._keyupHandler.bind(this);
257-
this._followToggle = this._followToggle.bind(this);
258-
this._addImage = this._addImage.bind(this);
259-
260-
this.button = this.shadowRoot.querySelector("button");
261-
262-
if (this.button) {
263-
this.button.addEventListener("click", this._clickHandler);
264-
this.button.addEventListener("keyup", this._keyupHandler);
265-
}
266-
267-
this.profilePic = this.shadowRoot.querySelector("#profile-pic");
268-
}
269-
270-
_followToggle() {
271-
this.button.textContent = this.following ? "Unfollow" : "Follow";
272-
}
273-
274-
_addImage(newImage) {
275-
this.profilePic.style.backgroundImage = `url(${newImage})`;
276-
}
277-
278-
attributeChangedCallback(name, oldValue, newValue) {
279-
switch (name) {
280-
case "following":
281-
this._followToggle();
282-
break;
283-
284-
case "photo-url":
285-
this._addImage(newValue);
286-
break;
287-
}
288-
}
289-
290-
disconnectedCallback() {
291-
if (this.button) {
292-
this.button.removeEventListener("click", this._clickHandler);
293-
this.button.removeEventListener("keyup", this._keyupHandler);
294-
}
295-
}
296-
297-
_clickHandler(event) {
298-
this.follow(event);
299-
}
300-
301-
// On enter press, trigger follow event
302-
_keyupHandler(event) {
303-
let key = event.key || event.keyCode;
304-
switch (key) {
305-
case "Enter":
306-
case 13:
307-
this.follow(event);
308-
}
309-
}
310-
}
311-
312-
PFElement.create(PfeCoolElement);
313-
314-
export default PfeCoolElement;
315-
```
316-
317183
Now that our code works, we should create tests to ensure our element works as we iterate on it in the future.
318184

319185
[Move to Step 3: Test](../step-3)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ class PfeModal extends PFElement {
4141
// These fire custom events
4242
this.open = this.open.bind(this);
4343
this.close = this.close.bind(this);
44+
this._init = this._init.bind(this);
4445

4546
this._modalWindow = this.shadowRoot.querySelector(`.${this.tag}__window`);
4647
this._modalCloseButton = this.shadowRoot.querySelector(`.${this.tag}__close`);
4748
this._overlay = this.shadowRoot.querySelector(`.${this.tag}__overlay`);
4849
this._container = this.shadowRoot.querySelector(`.${this.tag}__container`);
4950
this._outer = this.shadowRoot.querySelector(`.${this.tag}__outer`);
5051

51-
this._observer = new MutationObserver(() => {
52-
this._mapSchemaToSlots(this.tag, this.slots);
53-
this._init();
54-
});
52+
this._observer = new MutationObserver(this._init);
5553
}
5654

5755
connectedCallback() {
@@ -83,6 +81,8 @@ class PfeModal extends PFElement {
8381
}
8482

8583
_init() {
84+
if (window.ShadyCSS) this._observer.disconnect();
85+
8686
this.trigger = this.querySelector(`[slot="${this.tag}--trigger"]`);
8787
this.header = this.querySelector(`[slot="${this.tag}--header"]`);
8888
this.body = [...this.querySelectorAll(`*:not([slot])`)];
@@ -105,6 +105,8 @@ class PfeModal extends PFElement {
105105
this._modalWindow.setAttribute("aria-label", this.trigger.innerText);
106106
}
107107
}
108+
109+
if (window.ShadyCSS) this._observer.observe(this, { childList: true });
108110
}
109111

110112
_keydownHandler(event) {

0 commit comments

Comments
 (0)