Skip to content

Commit

Permalink
Check layout on initial load, doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Sep 27, 2024
1 parent 8757e2f commit cddf61d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/assets/js/playground/split-view.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {SplitView} from '@spectrum-web-components/split-view';
import '@spectrum-web-components/split-view/sp-split-view.js';

export default function setup(): void {
/**
* Make split views responsive and stack vertically on narrow screens.
*/
export default function setupSplitView(): void {
// 60em = --sl-breakpoint--large
const mql = window.matchMedia('(max-width: 60em');
mql.addEventListener('change', event => {
const topSplit = document.querySelector('.sl-c-playground') as SplitView;
const topSplit = document.querySelector('.sl-c-playground') as SplitView;

function updateLayout(event: MediaQueryListEvent | MediaQueryList): void {
if (topSplit) topSplit.vertical = event.matches;
});
}
updateLayout(mql);
mql.addEventListener('change', updateLayout);
}

0 comments on commit cddf61d

Please sign in to comment.