Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion components/page/demo/page-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import '../../selection/selection-action.js';
import '../../switch/switch-visibility.js';
import '../../switch/switch.js';
import '../../table/table-controls.js';
import '../page.js';
import '../page-footer.js';
import '../page-main.js';
import '../page-side-nav.js';
import '../page-supporting.js';
import './page-header-full.js';
import { css, html, LitElement, nothing } from 'lit';
import { _forceLegacyBrowserMode } from '../page.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { inputLabelStyles } from '../../inputs/input-label-styles.js';
import { pageHeaderImmersiveActionsDemo } from '../test/page-header-immersive-fixtures.js';
Expand All @@ -52,6 +52,7 @@ class PageDemo extends LitElement {
header: { type: String, attribute: 'header' },
immersiveHeaderTitleType: { type: String, attribute: 'immersive-header-title-type' },
layout: { type: String, attribute: 'layout' },
legacyBrowserMode: { type: String, attribute: 'legacy-browser-mode' },
widthType: { type: String, attribute: 'width-type' },
_mainDialogOpened: { state: true },
_mainToastOpened: { state: true },
Expand Down Expand Up @@ -86,6 +87,8 @@ class PageDemo extends LitElement {
this.header = urlParams.get('header') || 'full';
this.immersiveHeaderTitleType = urlParams.get('immersiveHeaderTitleType') || 'title-subtitle';
this.layout = urlParams.get('layout') || 'main-only';
this.legacyBrowserMode = urlParams.has('legacyBrowserMode');
if (this.legacyBrowserMode) _forceLegacyBrowserMode(true);
this.widthType = urlParams.get('widthType') || 'normal';
this._mainDialogOpened = false;
this._mainToastOpened = false;
Expand Down Expand Up @@ -124,6 +127,13 @@ class PageDemo extends LitElement {
this.#updateUrlParam('layout', this.layout);
}

#handleLegacyBrowserModeChange(e) {
this.legacyBrowserMode = e.target.on;
_forceLegacyBrowserMode(this.legacyBrowserMode);
this.#updateUrlParamBool('legacyBrowserMode', this.legacyBrowserMode);
this.shadowRoot.querySelector('d2l-page')?.requestUpdate();
}

#handleMainDialogClose() {
this._mainDialogOpened = false;
this._mainToastOpened = true;
Expand Down Expand Up @@ -251,6 +261,9 @@ class PageDemo extends LitElement {
${this.layout === 'side-nav' ? html`<d2l-switch text="Side Nav" data-key="hasSideNavHeader" @change="${this.#handleVisibilityChange}" ?on="${this.hasSideNavHeader}"></d2l-switch>` : nothing}
${this.layout === 'supporting' ? html`<d2l-switch text="Supporting" data-key="hasSupportingHeader" @change="${this.#handleVisibilityChange}" ?on="${this.hasSupportingHeader}"></d2l-switch>` : nothing}
</d2l-input-fieldset>
<d2l-input-fieldset label="Legacy Browser Mode">
<d2l-switch text="On" @change="${this.#handleLegacyBrowserModeChange}" ?on="${this.legacyBrowserMode}"></d2l-switch>
</d2l-input-fieldset>
</div>
</d2l-input-fieldset>
${this.#renderDemoHeaderControls()}
Expand Down
2 changes: 1 addition & 1 deletion components/page/page-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PageMain extends PagePanelMixin(LitElement) {

static styles = [pagePanelStyles, css`
.panel-header {
top: var(--d2l-page-header-height, 0);
top: var(--d2l-page-main-sticky-top, 0);
}
`];

Expand Down
64 changes: 58 additions & 6 deletions components/page/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ const DRAWER_MIN_HEIGHT = 200; // TO DO: Confirm
const MAIN_MIN_WIDTH = 600; // TO DO: Confirm
const PANEL_MIN_WIDTH = 320;

/*
* Legacy Browser Mode can be deleted once we have hard-blocked all browsers that do not support the Popover api,
* and dialog will be able to escape stacking contexts. It creates a "scrolling container" layout for pages with panels,
* to avoid the stacking context created by position: sticky.
*/
let forceLegacyBrowserMode = false;
const isPopoverSupported = ('popover' in HTMLElement.prototype);
function isLegacyBrowserMode() {
return forceLegacyBrowserMode || !isPopoverSupported;
}
// Back door for the demo page and unit tests to force legacy browser mode, bypassing popover feature detection.
// DO NOT use in production.
export function _forceLegacyBrowserMode(on) {
forceLegacyBrowserMode = on;
}

class PanelStateController {
constructor(host, panelConfigs) {
this.#host = host;
Expand Down Expand Up @@ -117,11 +133,12 @@ class Page extends ProviderMixin(LocalizeCoreElement(LitElement)) {
max-width: var(--d2l-page-content-max-width, 100%);
padding-bottom: var(--d2l-page-footer-height, 0); /* Reserve space for fixed footer */
}
.content.has-panels {
.page.has-panels .content {
min-height: calc(100vh - var(--d2l-page-header-height-measured, 0px));
}

main {
--d2l-page-main-sticky-top: var(--d2l-page-header-height, 0);
flex: 1;
min-width: min(${MAIN_MIN_WIDTH}px, 100%);
}
Expand Down Expand Up @@ -160,6 +177,43 @@ class Page extends ProviderMixin(LocalizeCoreElement(LitElement)) {
margin-inline: var(--d2l-page-margin-inline, 0);
max-width: var(--d2l-page-footer-max-width, 100%);
}

/* Legacy Browser Mode */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm shocked at how few changes this required, and it's awesome that they're (mostly) just CSS. 🎉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm worried it'll get messier once all functionality is in, but it's for super old browsers anyways - we could degrade that stuff gracefully too and not support everything one-on-one.

.page.legacy-browser-mode.has-panels {
display: flex;
flex-direction: column;
height: 100vh;
}
.page.legacy-browser-mode.has-panels .header,
.page.legacy-browser-mode.header-sticky.has-panels .header {
flex: 0 0 auto;
position: static;
}
.page.legacy-browser-mode.has-panels .content {
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
padding-bottom: 0;
width: 100%;
}
.page.legacy-browser-mode.has-panels main {
--d2l-page-main-sticky-top: 0; /* Header is static and content scrolls within main, so panel headers stick to the top of the scroll container */
min-height: 0;
overflow: auto;
}
.page.legacy-browser-mode.has-panels .side-nav-panel,
.page.legacy-browser-mode.has-panels .supporting-panel,
.page.legacy-browser-mode.has-panels .divider {
max-height: none;
min-height: 0;
position: static;
}
.page.legacy-browser-mode.has-panels .footer {
flex: 0 0 auto;
}
.page.legacy-browser-mode.has-panels .fixed-footer {
position: static;
}
`;

constructor() {
Expand Down Expand Up @@ -229,17 +283,15 @@ class Page extends ProviderMixin(LocalizeCoreElement(LitElement)) {
render() {
const pageClasses = {
'page': true,
'header-sticky': this._headerIsSticky
};
const contentClasses = {
'content': true,
'header-sticky': this._headerIsSticky,
'legacy-browser-mode': isLegacyBrowserMode(),
'has-panels': this._slotVisibility['side-nav'] || this._slotVisibility['supporting']
};

return html`
<div class="${classMap(pageClasses)}">
${this.#renderHeader()}
<div class="${classMap(contentClasses)}">
<div class="content">
${this.#renderSideNavPanel()}
<main><slot></slot></main>
${this.#renderSupportingPanel()}
Expand Down