Skip to content

Commit a368459

Browse files
committed
fix: fall back to seeing the current pattern's query string to all or the defaultPattern value if undefined when the iframe page initially loads
1 parent d645ea1 commit a368459

File tree

1 file changed

+10
-7
lines changed
  • packages/uikit-workshop/src/scripts/components/pl-viewport

1 file changed

+10
-7
lines changed

packages/uikit-workshop/src/scripts/components/pl-viewport/pl-viewport.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ class IFrame extends BaseComponent {
5353

5454
// update the currently active nav + add / update the page's query string
5555
handlePageLoad(e) {
56-
var queryString = window.location.search;
56+
const queryString = window.location.search;
5757
const urlParams = new URLSearchParams(queryString);
58-
let patternParam = urlParams.get('p');
58+
const patternParam = urlParams.get('p');
5959

60-
if (e.detail.pattern) {
61-
document.title = 'Pattern Lab - ' + e.detail.pattern;
60+
const currentPattern =
61+
e.detail.pattern || window.config.defaultPattern || 'all';
62+
63+
if (currentPattern) {
64+
document.title = 'Pattern Lab - ' + currentPattern;
6265

6366
const addressReplacement =
6467
window.location.protocol === 'file:'
@@ -68,21 +71,21 @@ class IFrame extends BaseComponent {
6871
window.location.host +
6972
window.location.pathname.replace('index.html', '') +
7073
'?p=' +
71-
e.detail.pattern;
74+
currentPattern;
7275

7376
// first time hitting a PL page -- no query string on the current page
7477
if (patternParam === null) {
7578
window.history.replaceState(
7679
{
77-
currentPattern: e.detail.pattern,
80+
currentPattern: currentPattern,
7881
},
7982
null,
8083
addressReplacement
8184
);
8285
} else {
8386
window.history.replaceState(
8487
{
85-
currentPattern: e.detail.pattern,
88+
currentPattern: currentPattern,
8689
},
8790
null,
8891
addressReplacement

0 commit comments

Comments
 (0)