Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide the dev toolbar on print #11496

Merged
merged 3 commits into from
Jul 18, 2024
Merged
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
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
Loading