From 1f38d9508cebdc62ff3b6b9a36b72942b5953901 Mon Sep 17 00:00:00 2001 From: Abdulrahman Alfawal <61620817+alfawal@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:26:15 +0300 Subject: [PATCH 1/3] Hide the dev toolbar on print --- packages/astro/src/runtime/client/dev-toolbar/toolbar.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts index 13505f11cdc5..3f9db6b1dc7b 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts @@ -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), From 4958057cc9ea4f7989e648568c04b2dd1db65f00 Mon Sep 17 00:00:00 2001 From: Abdulrahman Alfawal <61620817+alfawal@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:40:34 +0300 Subject: [PATCH 2/3] Run checkset --- .changeset/orange-boats-trade.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/orange-boats-trade.md diff --git a/.changeset/orange-boats-trade.md b/.changeset/orange-boats-trade.md new file mode 100644 index 000000000000..8f284bc9ada6 --- /dev/null +++ b/.changeset/orange-boats-trade.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Hide the dev toolbar on `window.print()` (CTRL + P) From fc0568c1eb5e4ad11eaee49875665ba449f65166 Mon Sep 17 00:00:00 2001 From: Abdulrahman Alfawal <61620817+alfawal@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:38:11 +0300 Subject: [PATCH 3/3] Add a test case --- packages/astro/e2e/dev-toolbar.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/astro/e2e/dev-toolbar.test.js b/packages/astro/e2e/dev-toolbar.test.js index 7c90384d437a..305577852323 100644 --- a/packages/astro/e2e/dev-toolbar.test.js +++ b/packages/astro/e2e/dev-toolbar.test.js @@ -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(); + }); });