Skip to content

Commit 451b94b

Browse files
authored
fix(docs): keep the demo's full screen view in the browser window (#1275)
# 📝 PR Overview On macOS, the live demo's Full screen button used the browser Fullscreen API. The demo took over the whole desktop as a new Space, and the docs site navigation was no longer reachable. The demo now fills the browser window below the docs navbar. The navbar stays on top and usable, and exit puts you back at the same scroll position. ## 🛠️ Changes made - Full screen toggles an in-page expanded state, not the Fullscreen API — the view stays in the browser window. - Only an inner panel goes `position: fixed`; the figure keeps its place in the page — otherwise scroll anchoring jumps the page about 870px on exit. - The announcement bar is hidden while expanded — the navbar then always sits at the top, so the panel can start at `--ifm-navbar-height` with no JS measurement. - Page scroll is locked while expanded — a wheel over the demo's bar can no longer move the hidden page. - The controls bar stays visible when an expanded demo is narrowed to 768px or less — before, Exit and Close disappeared. - The toggle carries `aria-expanded`. ## 🧩 Type of change (check all applicable) - [x] 🐛 Bug fix - something not working as expected - [ ] ✨ New feature – adds new functionality - [ ] ♻️ Refactor - internal changes with no user impact - [ ] ⚡ Performance Improvement - [ ] 📝 Documentation - README or documentation site changes - [ ] 🔧 Chore - dev tooling, CI, config - [ ] 💥 Breaking change ## 📷 Screenshots / gifs / video [optional] N/A ## 🔗 Related Issues N/A ## ✅ Tests added? - [x] 👍 yes - [ ] 🙅 no, not needed - [ ] 🙋 no, I need help ## 📚 Docs updated? - [ ] 🔖 README.md - [ ] 🔖 CHANGELOG.md - [ ] 📖 help site - [ ] 🧪 Marked any pre-release-only features (README `🧪` badge — see [RELEASING.md](../RELEASING.md#-marking-pre-release-only-features)) - [x] 🙅 not needed ## Anything else we need to know? [optional] Test plan: - `pnpm exec jest --selectProjects docs` — 34 pass. New tests: Full screen does not call `requestFullscreen`, Exit returns to the page, and close then reopen starts at page size. - Manual, in Chrome on `pnpm start` in `lana-docs`: open the demo, then Full screen. The panel fills the window below the navbar and the Docs dropdown opens over it. Exit from scroll positions 0, 300, 600 and 900 returns to the same position. Narrow the window to 700px while expanded: Exit stays visible. Pre-existing, not fixed here: - `lana-docs/src/css/custom.css:90` matches the announcement bar by its hashed class (`div[class^='announcementBar_']`). The stable class is `.theme-announcement-bar`. - After Close demo, keyboard focus falls to `<body>` instead of the Open demo button.
1 parent 02efd00 commit 451b94b

3 files changed

Lines changed: 132 additions & 81 deletions

File tree

‎lana-docs/src/components/home/LiveDemo/__tests__/LiveDemo.test.tsx‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeAll, beforeEach, expect, it, jest } from '@jest/globals';
1+
import { afterEach, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
22
import { act } from 'react';
33
import { createRoot, type Root } from 'react-dom/client';
44

@@ -125,6 +125,47 @@ it('closes the demo and shows the poster again', async () => {
125125
expect(button('Open demo')).toBeDefined();
126126
});
127127

128+
describe('full screen', () => {
129+
const requestFullscreen = jest.fn();
130+
131+
beforeEach(() => {
132+
// jsdom has no Fullscreen API.
133+
Element.prototype.requestFullscreen = requestFullscreen as never;
134+
requestFullscreen.mockClear();
135+
});
136+
137+
it('expands within the browser window instead of taking over the screen', async () => {
138+
render();
139+
await click(button('Open demo'));
140+
141+
await click(button('Full screen'));
142+
143+
expect(requestFullscreen).not.toHaveBeenCalled();
144+
expect(button('Exit full screen').getAttribute('aria-expanded')).toBe('true');
145+
});
146+
147+
it('returns to the page from Exit full screen', async () => {
148+
render();
149+
await click(button('Open demo'));
150+
await click(button('Full screen'));
151+
152+
await click(button('Exit full screen'));
153+
154+
expect(button('Full screen').getAttribute('aria-expanded')).toBe('false');
155+
});
156+
157+
it('reopens at page size after closing in full screen', async () => {
158+
render();
159+
await click(button('Open demo'));
160+
await click(button('Full screen'));
161+
162+
await click(button('Close demo'));
163+
await click(button('Open demo'));
164+
165+
expect(button('Full screen').getAttribute('aria-expanded')).toBe('false');
166+
});
167+
});
168+
128169
it('keeps the poster and gives the build steps in dev when the demo is not built', async () => {
129170
const env = process.env.NODE_ENV;
130171
process.env.NODE_ENV = 'development';

‎lana-docs/src/components/home/LiveDemo/index.tsx‎

Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export default function LiveDemo(): ReactElement {
2121
const demoUrl = useBaseUrl('/demo/viewer.html');
2222
const settingsUrl = useBaseUrl('/demo/settings.json');
2323
const [missing, setMissing] = useState(false);
24-
const figure = useRef<HTMLElement>(null);
2524
const frame = useRef<HTMLIFrameElement>(null);
2625
// The theme at launch goes in the URL; later toggles are posted, so the frame never reloads.
2726
const [launchTheme, setLaunchTheme] = useState<string | null>(null);
28-
const [fullscreen, setFullscreen] = useState(false);
27+
const [expanded, setExpanded] = useState(false);
2928

3029
const syncTheme = useCallback(() => {
3130
frame.current?.contentWindow?.postMessage(
@@ -36,12 +35,6 @@ export default function LiveDemo(): ReactElement {
3635

3736
useEffect(syncTheme, [syncTheme]);
3837

39-
useEffect(() => {
40-
const onChange = () => setFullscreen(document.fullscreenElement === figure.current);
41-
document.addEventListener('fullscreenchange', onChange);
42-
return () => document.removeEventListener('fullscreenchange', onChange);
43-
}, []);
44-
4538
const launch = async () => {
4639
const theme = colorMode;
4740
const built = await isDemoBuilt(settingsUrl);
@@ -50,79 +43,78 @@ export default function LiveDemo(): ReactElement {
5043
setLaunchTheme(theme);
5144
}
5245
};
53-
const toggleFullscreen = () =>
54-
fullscreen ? void document.exitFullscreen() : void figure.current?.requestFullscreen();
5546
const close = () => {
56-
if (fullscreen) {
57-
void document.exitFullscreen();
58-
}
47+
setExpanded(false);
5948
setLaunchTheme(null);
6049
};
6150

6251
return (
63-
<figure ref={figure} className={clsx(styles.demo, launchTheme && styles.live)}>
64-
<div className={styles.bar}>
65-
{!launchTheme && !missing && (
66-
<button type="button" className="button button--primary" onClick={() => void launch()}>
67-
Open demo
68-
</button>
69-
)}
70-
{missing ? (
71-
<span role="status" className={styles.label}>
72-
{process.env.NODE_ENV === 'development' ? (
73-
<>
74-
<strong>Demo not built.</strong> Run <code>pnpm build</code>, then{' '}
75-
<code>pnpm --filter docs-site build:demo</code>, and reload.
76-
</>
77-
) : (
78-
<>
79-
<strong>The live demo is not available right now.</strong>{' '}
80-
<a href={MARKETPLACE_URL}>Install the extension</a> to try it on your own logs.
81-
</>
82-
)}
83-
</span>
84-
) : (
85-
<span className={styles.label}>
86-
<strong>Live demo</strong> of a 20 MB sample log, in your browser
87-
</span>
88-
)}
89-
{launchTheme && (
90-
<span className={styles.controls}>
91-
<button
92-
type="button"
93-
className="button button--secondary button--sm"
94-
onClick={toggleFullscreen}
95-
>
96-
{fullscreen ? 'Exit full screen' : 'Full screen'}
97-
</button>
98-
<button type="button" className="button button--secondary button--sm" onClick={close}>
99-
Close demo
52+
<figure className={clsx(styles.demo, launchTheme && styles.live, expanded && styles.expanded)}>
53+
<div className={styles.panel}>
54+
<div className={styles.bar}>
55+
{!launchTheme && !missing && (
56+
<button type="button" className="button button--primary" onClick={() => void launch()}>
57+
Open demo
10058
</button>
101-
</span>
59+
)}
60+
{missing ? (
61+
<span role="status" className={styles.label}>
62+
{process.env.NODE_ENV === 'development' ? (
63+
<>
64+
<strong>Demo not built.</strong> Run <code>pnpm build</code>, then{' '}
65+
<code>pnpm --filter docs-site build:demo</code>, and reload.
66+
</>
67+
) : (
68+
<>
69+
<strong>The live demo is not available right now.</strong>{' '}
70+
<a href={MARKETPLACE_URL}>Install the extension</a> to try it on your own logs.
71+
</>
72+
)}
73+
</span>
74+
) : (
75+
<span className={styles.label}>
76+
<strong>Live demo</strong> of a 20 MB sample log, in your browser
77+
</span>
78+
)}
79+
{launchTheme && (
80+
<span className={styles.controls}>
81+
<button
82+
type="button"
83+
className="button button--secondary button--sm"
84+
aria-expanded={expanded}
85+
onClick={() => setExpanded(!expanded)}
86+
>
87+
{expanded ? 'Exit full screen' : 'Full screen'}
88+
</button>
89+
<button type="button" className="button button--secondary button--sm" onClick={close}>
90+
Close demo
91+
</button>
92+
</span>
93+
)}
94+
</div>
95+
{launchTheme ? (
96+
<iframe
97+
ref={frame}
98+
title="Apex Log Analyzer live demo"
99+
src={`${demoUrl}?theme=${launchTheme}`}
100+
onLoad={syncTheme}
101+
/>
102+
) : (
103+
// A mouse shortcut only; the Open demo button is the keyboard and screen reader path.
104+
<div className={styles.poster} onClick={() => void launch()}>
105+
<ThemedImage
106+
sources={{
107+
dark: `${ASSETS_URL}/timeline.png`,
108+
light: `${ASSETS_URL}/timeline-light.png`,
109+
}}
110+
alt="Apex Log Analyzer showing a 24.6 second transaction: the Timeline flame chart with its minimap and governor limits strip, beside the Inspector overview"
111+
width={1920}
112+
height={1023}
113+
fetchPriority="high"
114+
/>
115+
</div>
102116
)}
103117
</div>
104-
{launchTheme ? (
105-
<iframe
106-
ref={frame}
107-
title="Apex Log Analyzer live demo"
108-
src={`${demoUrl}?theme=${launchTheme}`}
109-
onLoad={syncTheme}
110-
/>
111-
) : (
112-
// A mouse shortcut only; the Open demo button is the keyboard and screen reader path.
113-
<div className={styles.poster} onClick={() => void launch()}>
114-
<ThemedImage
115-
sources={{
116-
dark: `${ASSETS_URL}/timeline.png`,
117-
light: `${ASSETS_URL}/timeline-light.png`,
118-
}}
119-
alt="Apex Log Analyzer showing a 24.6 second transaction: the Timeline flame chart with its minimap and governor limits strip, beside the Inspector overview"
120-
width={1920}
121-
height={1023}
122-
fetchPriority="high"
123-
/>
124-
</div>
125-
)}
126118
</figure>
127119
);
128120
}

‎lana-docs/src/components/home/LiveDemo/styles.module.css‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,47 @@
5151
}
5252

5353
.live {
54-
display: flex;
55-
flex-direction: column;
5654
height: min(85vh, 960px);
5755
border-bottom: 1px solid var(--lana-rule);
5856
border-radius: 10px;
5957
}
6058

59+
.live .panel {
60+
display: flex;
61+
flex-direction: column;
62+
height: 100%;
63+
}
64+
6165
.live iframe {
6266
display: block;
6367
flex: 1;
6468
width: 100%;
6569
border: 0;
6670
}
6771

68-
.live:fullscreen {
69-
height: 100vh;
70-
border: 0;
71-
border-radius: 0;
72+
/* Not the Fullscreen API, which takes the macOS desktop; the figure stays in flow, or scroll anchoring jumps on exit. */
73+
.expanded .panel {
74+
position: fixed;
75+
inset: var(--ifm-navbar-height) 0 0;
76+
z-index: calc(var(--ifm-z-index-fixed) - 1);
77+
height: auto;
78+
background: var(--ifm-background-color);
79+
}
80+
81+
/* Stops a wheel over the bar from scrolling the hidden page, which would move the demo on exit. */
82+
:global(html):has(.expanded) {
83+
overflow: hidden;
84+
}
85+
86+
/* The banner sits above the sticky navbar; hiding it keeps the navbar at a fixed top edge. */
87+
:global(html):has(.expanded) :global(.theme-announcement-bar) {
88+
display: none;
7289
}
7390

7491
/* The viewer needs a desktop-sized window, so small screens keep the screenshot only. */
7592
@media (max-width: 768px) {
76-
.bar {
93+
/* An expanded demo keeps its bar, or a narrowed window leaves no way out. */
94+
.demo:not(.expanded) .bar {
7795
display: none;
7896
}
7997

0 commit comments

Comments
 (0)