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

Toggle dev toolbar hitbox height when toolbar is visible #9446

Merged
merged 3 commits into from
Dec 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-wasps-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Toggle dev toolbar hitbox height when toolbar is visible
9 changes: 7 additions & 2 deletions packages/astro/src/runtime/client/dev-overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type DevOverlayPlugin = DevOverlayPluginDefinition & {
const WS_EVENT_NAME = 'astro-dev-toolbar';
const WS_EVENT_NAME_DEPRECATED = 'astro-dev-overlay';
const HOVER_DELAY = 2 * 1000;
const DEVBAR_HITBOX_ABOVE = 42;

export class AstroDevOverlay extends HTMLElement {
shadowRoot: ShadowRoot;
Expand Down Expand Up @@ -80,7 +81,7 @@ export class AstroDevOverlay extends HTMLElement {
pointer-events: auto;
}
#dev-bar-hitbox-above {
height: 42px;
height: ${DEVBAR_HITBOX_ABOVE}px;
}
#dev-bar-hitbox-below {
height: 16px;
Expand Down Expand Up @@ -149,7 +150,7 @@ export class AstroDevOverlay extends HTMLElement {
border-radius: 4px;
padding: 4px 8px;
position: absolute;
top: 4px;
top: ${4 - DEVBAR_HITBOX_ABOVE}px;
font-size: 14px;
opacity: 0;
transition: opacity 0.2s ease-in-out 0s;
Expand Down Expand Up @@ -492,16 +493,20 @@ export class AstroDevOverlay extends HTMLElement {
setOverlayVisible(newStatus: boolean) {
const barContainer = this.shadowRoot.querySelector<HTMLDivElement>('#bar-container');
const devBar = this.shadowRoot.querySelector<HTMLDivElement>('#dev-bar');
const devBarHitboxAbove =
this.shadowRoot.querySelector<HTMLDivElement>('#dev-bar-hitbox-above');
if (newStatus === true) {
this.devOverlay?.removeAttribute('data-hidden');
barContainer?.removeAttribute('inert');
devBar?.removeAttribute('tabindex');
if (devBarHitboxAbove) devBarHitboxAbove.style.height = '0';
return;
}
if (newStatus === false) {
this.devOverlay?.setAttribute('data-hidden', '');
barContainer?.setAttribute('inert', '');
devBar?.setAttribute('tabindex', '0');
if (devBarHitboxAbove) devBarHitboxAbove.style.height = `${DEVBAR_HITBOX_ABOVE}px`;
return;
}
}
Expand Down