Skip to content

Commit cc154c3

Browse files
committed
fix(oc-docs): dismiss playground overlay sidebar on outside click and fix dark-mode shadow
The inline-dock sidebar overlays the view but only closed on navigation, so a click outside it did nothing. Add a backdrop that closes it, mirroring the docs navigation drawer. Also swap the overlay's text-tinted color-mix shadow (which turned whitish in dark mode) for the theme-aware --oc-shadow-md token, drop the doubled border-right in overlay mode, and move the docs drawer onto the same token.
1 parent d926e0d commit cc154c3

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎packages/oc-docs/e2e/components/playground.component.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class PlaygroundComponent extends BaseComponent {
1515
readonly runner = this.page.getByTestId('playground-runner');
1616
readonly loadError = this.page.getByTestId('playground-load-error');
1717
readonly sidebarPanel = this.page.getByTestId('playground-sidebar-panel');
18+
readonly sidebarBackdrop = this.page.getByTestId('playground-sidebar-backdrop');
1819
readonly collectionNode = this.page.getByTestId('sidebar-collection-root');
1920
readonly collectionCollapseToggle = this.collectionNode.getByRole('button', {
2021
name: /Collapse collection|Expand collection/,

‎packages/oc-docs/e2e/tests/playground/playground.spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ test.describe('playground docks (desktop)', () => {
183183
expect(viewBox!.x).toBeLessThanOrEqual(sideBox!.x + 5);
184184
});
185185

186+
test('inline dock: clicking outside the overlay sidebar closes it', async ({ page, playground }) => {
187+
await page.goto(openAt('inline'));
188+
await playground.sidebarToggle.click();
189+
await expect(playground.sidebarPanel).toBeVisible();
190+
// Click the view area outside the sidebar (its backdrop), mirroring the docs
191+
// navigation drawer: an outside click dismisses the overlay. The backdrop
192+
// spans the whole dock from its left edge, so click just past the sidebar's
193+
// right edge to land on the exposed view area, not the panel.
194+
const side = await playground.sidebarPanel.boundingBox();
195+
await playground.sidebarBackdrop.click({ position: { x: side!.width + 40, y: 30 } });
196+
await expect(playground.sidebarPanel).toHaveCount(0);
197+
});
198+
186199
test('inline dock: selecting a request auto-closes the overlay sidebar', async ({ page, playground }) => {
187200
await page.goto(openAt('inline'));
188201
await playground.sidebarToggle.click();

‎packages/oc-docs/src/components/Playground/PlaygroundBody/PlaygroundBody.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ const PlaygroundBody: React.FC<PlaygroundBodyProps> = ({
225225

226226
return (
227227
<StyledWrapper data-testid="playground-runner" data-overlay-sidebar={dock === 'inline' ? 'true' : undefined}>
228+
{sidebarOpen && dock === 'inline' && (
229+
// In the inline dock the sidebar overlays the view, so a click outside it
230+
// dismisses it, same as the docs navigation drawer's backdrop.
231+
<div
232+
className="sidebar-backdrop"
233+
data-testid="playground-sidebar-backdrop"
234+
aria-hidden="true"
235+
onClick={onCloseSidebar}
236+
/>
237+
)}
228238
{sidebarOpen && (
229239
<aside className="sidebar" data-testid="playground-sidebar-panel">
230240
<PlaygroundSidebar

‎packages/oc-docs/src/components/Playground/PlaygroundBody/StyledWrapper.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,25 @@ export const StyledWrapper = styled.div`
3838
position: relative;
3939
}
4040
41+
&[data-overlay-sidebar='true'] .sidebar-backdrop {
42+
position: absolute;
43+
inset: 0;
44+
z-index: 4;
45+
}
46+
4147
&[data-overlay-sidebar='true'] .sidebar {
4248
position: absolute;
4349
top: 0;
4450
left: 0;
4551
bottom: 0;
4652
z-index: 5;
4753
background-color: var(--oc-background-base);
48-
box-shadow: 2px 0 8px color-mix(in srgb, var(--oc-text) 12%, transparent);
54+
/* Overlay floats above the view, so the shadow alone separates it; drop the
55+
base border-right to avoid a doubled edge. Theme-aware shadow token so it
56+
reads dark in both themes, instead of a text-tinted mix that turns whitish
57+
in dark mode. */
58+
border-right: none;
59+
box-shadow: var(--oc-shadow-md);
4960
}
5061
5162
&[data-overlay-sidebar='true'] .view {

‎packages/oc-docs/src/components/SidebarDrawer/StyledWrapper.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const StyledWrapper = styled.div`
2626
z-index: calc(var(--z-overlay, 50) + 1);
2727
background-color: var(--oc-background-base);
2828
border-right: 1px solid var(--oc-border-border0);
29-
box-shadow: var(--shadow-md);
29+
box-shadow: var(--oc-shadow-md);
3030
transform: translateX(-100%);
3131
visibility: hidden;
3232
pointer-events: none;

0 commit comments

Comments
 (0)