Skip to content

Commit ede3f7f

Browse files
alexnguyennzflorian-lefebvre
andauthoredDec 29, 2023
Toggle dev toolbar hitbox height when toolbar is visible (#9446)
* Toggle dev toolbar hitbox height when toolbar is visible * Add hitbox above height const --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
1 parent a2977cb commit ede3f7f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎.changeset/silent-wasps-learn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Toggle dev toolbar hitbox height when toolbar is visible

‎packages/astro/src/runtime/client/dev-overlay/overlay.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type DevOverlayPlugin = DevOverlayPluginDefinition & {
1818
const WS_EVENT_NAME = 'astro-dev-toolbar';
1919
const WS_EVENT_NAME_DEPRECATED = 'astro-dev-overlay';
2020
const HOVER_DELAY = 2 * 1000;
21+
const DEVBAR_HITBOX_ABOVE = 42;
2122

2223
export class AstroDevOverlay extends HTMLElement {
2324
shadowRoot: ShadowRoot;
@@ -80,7 +81,7 @@ export class AstroDevOverlay extends HTMLElement {
8081
pointer-events: auto;
8182
}
8283
#dev-bar-hitbox-above {
83-
height: 42px;
84+
height: ${DEVBAR_HITBOX_ABOVE}px;
8485
}
8586
#dev-bar-hitbox-below {
8687
height: 16px;
@@ -149,7 +150,7 @@ export class AstroDevOverlay extends HTMLElement {
149150
border-radius: 4px;
150151
padding: 4px 8px;
151152
position: absolute;
152-
top: 4px;
153+
top: ${4 - DEVBAR_HITBOX_ABOVE}px;
153154
font-size: 14px;
154155
opacity: 0;
155156
transition: opacity 0.2s ease-in-out 0s;
@@ -492,16 +493,20 @@ export class AstroDevOverlay extends HTMLElement {
492493
setOverlayVisible(newStatus: boolean) {
493494
const barContainer = this.shadowRoot.querySelector<HTMLDivElement>('#bar-container');
494495
const devBar = this.shadowRoot.querySelector<HTMLDivElement>('#dev-bar');
496+
const devBarHitboxAbove =
497+
this.shadowRoot.querySelector<HTMLDivElement>('#dev-bar-hitbox-above');
495498
if (newStatus === true) {
496499
this.devOverlay?.removeAttribute('data-hidden');
497500
barContainer?.removeAttribute('inert');
498501
devBar?.removeAttribute('tabindex');
502+
if (devBarHitboxAbove) devBarHitboxAbove.style.height = '0';
499503
return;
500504
}
501505
if (newStatus === false) {
502506
this.devOverlay?.setAttribute('data-hidden', '');
503507
barContainer?.setAttribute('inert', '');
504508
devBar?.setAttribute('tabindex', '0');
509+
if (devBarHitboxAbove) devBarHitboxAbove.style.height = `${DEVBAR_HITBOX_ABOVE}px`;
505510
return;
506511
}
507512
}

0 commit comments

Comments
 (0)
Please sign in to comment.