Skip to content

Commit 9d602fe

Browse files
committed
feat: add support for auto-closing Nav when clicking inside of the rendered iframe
1 parent 447f054 commit 9d602fe

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Tiny helper script to listen for keyboard combos and to communicate back to the main Search component (via the Pattern Lab iframe)
2+
import Mousetrap from 'mousetrap';
3+
import { targetOrigin } from '../../utils';
4+
5+
document.addEventListener('click', function() {
6+
try {
7+
const obj = JSON.stringify({
8+
event: 'patternLab.pageClick',
9+
});
10+
window.parent.postMessage(obj, targetOrigin);
11+
} catch (error) {
12+
// @todo: how do we want to handle exceptions here?
13+
}
14+
});
15+
16+
Mousetrap.bind('esc', function(e) {
17+
try {
18+
const obj = JSON.stringify({
19+
event: 'patternLab.keyPress',
20+
key: e.key,
21+
altKey: e.altKey,
22+
ctrlKey: e.ctrlKey,
23+
metaKey: e.metaKey,
24+
shiftKey: e.shiftKey,
25+
});
26+
window.parent.postMessage(obj, targetOrigin);
27+
} catch (error) {
28+
// @todo: how do we want to handle exceptions here?
29+
}
30+
31+
return false;
32+
});

packages/uikit-workshop/src/scripts/patternlab-pattern.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import './utils/polyfills/custom-event-polyfill';
22
import './utils/polyfills/symbol-polyfill';
33
import './components/modal-styleguide';
44
import './components/pl-search/pl-search.iframe-helper';
5+
import './components/pl-nav/pl-nav.iframe-helper';
56
import './utils/share-inner-iframe-data';

0 commit comments

Comments
 (0)