Skip to content

Commit

Permalink
Hide the dev toolbar on print (#11496)
Browse files Browse the repository at this point in the history
* Hide the dev toolbar on print

* Run checkset

* Add a test case
  • Loading branch information
alfawal authored Jul 18, 2024
1 parent ee21ac7 commit 53ccd20
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-boats-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Hide the dev toolbar on `window.print()` (CTRL + P)
24 changes: 24 additions & 0 deletions packages/astro/e2e/dev-toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,28 @@ test.describe('Dev Toolbar', () => {
}
}
});

test('hidden on print media', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));

const toolbar = page.locator('astro-dev-toolbar');

const settingsAppButton = toolbar.locator('button[data-app-id="astro:settings"]');
await settingsAppButton.click();

const settingsAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:settings"]'
);
const settingsWindow = settingsAppCanvas.locator('astro-dev-toolbar-window');
await expect(settingsWindow).toBeVisible();

await page.emulateMedia({ media: 'print' });
await expect(settingsWindow).not.toBeVisible();

await page.emulateMedia({ media: 'screen' });
await expect(settingsWindow).toBeVisible();

await settingsAppButton.click();
await expect(settingsWindow).not.toBeVisible();
});
});
5 changes: 5 additions & 0 deletions packages/astro/src/runtime/client/dev-toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class AstroDevToolbar extends HTMLElement {
z-index: 999999;
view-transition-name: astro-dev-toolbar;
display: contents;
/* Hide the dev toolbar on window.print() (CTRL + P) */
@media print {
display: none;
}
}
::view-transition-old(astro-dev-toolbar),
Expand Down

0 comments on commit 53ccd20

Please sign in to comment.