Skip to content

Commit 634de59

Browse files
authored
Merge branch 'withastro:main' into main
2 parents 184ffb4 + 0ee255a commit 634de59

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

.changeset/beige-zebras-ring.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Add support for autocomplete attribute to the HTML button type.

.changeset/small-emus-deny.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Prevents dev toolbar tooltip from overflowing outside of the screen

packages/astro/astro-jsx.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ declare namespace astroHTML.JSX {
627627
}
628628

629629
interface ButtonHTMLAttributes extends HTMLAttributes {
630+
autocomplete?: string | undefined | null;
630631
disabled?: boolean | string | undefined | null;
631632
form?: string | undefined | null;
632633
formaction?: string | undefined | null;

packages/astro/e2e/dev-overlay.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,32 @@ test.describe('Dev Overlay', () => {
139139
await expect(auditWindow.locator('astro-dev-toolbar-icon[icon=check-circle]')).toBeVisible();
140140
});
141141

142+
test('adjusts tooltip position if off-screen', async ({ page, astro }) => {
143+
await page.goto(astro.resolveUrl('/tooltip-position'));
144+
145+
const overlay = page.locator('astro-dev-toolbar');
146+
const pluginButton = overlay.locator('button[data-plugin-id="astro:audit"]');
147+
await pluginButton.click();
148+
149+
const auditCanvas = overlay.locator(
150+
'astro-dev-toolbar-plugin-canvas[data-plugin-id="astro:audit"]'
151+
);
152+
const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight');
153+
for (const highlight of await auditHighlights.all()) {
154+
await expect(highlight).toBeVisible();
155+
await highlight.hover();
156+
const tooltip = highlight.locator('astro-dev-toolbar-tooltip');
157+
await expect(tooltip).toBeVisible();
158+
const tooltipBox = await tooltip.boundingBox();
159+
const { clientWidth, clientHeight } = await page.evaluate(() => ({
160+
clientWidth: document.documentElement.clientWidth,
161+
clientHeight: document.documentElement.clientHeight,
162+
}));
163+
expect(tooltipBox.x + tooltipBox.width).toBeLessThan(clientWidth);
164+
expect(tooltipBox.y + tooltipBox.height).toBeLessThan(clientHeight);
165+
}
166+
});
167+
142168
test('can open Settings plugin', async ({ page, astro }) => {
143169
await page.goto(astro.resolveUrl('/'));
144170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
3+
---
4+
5+
<div>
6+
<button role="top-left">Top left</button>
7+
<button role="top-right">Top right</button>
8+
<button role="bottom-left">Bottom left</button>
9+
<button role="bottom-right">Bottom right</button>
10+
</div>
11+
12+
<style>
13+
div {
14+
display: grid;
15+
grid-template-columns: auto auto;
16+
justify-content: space-between;
17+
align-content: space-between;
18+
height: 92vh;
19+
padding: 20px;
20+
}
21+
</style>

packages/astro/src/runtime/client/dev-overlay/plugins/utils/highlight.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ export function attachTooltipToHighlight(
5757
const originalRect = originalElement.getBoundingClientRect();
5858
const dialogRect = tooltip.getBoundingClientRect();
5959

60-
// If the tooltip is going to be off the screen, show it above the element instead
60+
// Prevent the tooltip from being off the screen
6161
if (originalRect.top < dialogRect.height) {
6262
// Not enough space above, show below
6363
tooltip.style.top = `${originalRect.height + 15}px`;
6464
} else {
6565
tooltip.style.top = `-${tooltip.offsetHeight}px`;
6666
}
67+
if (dialogRect.right > document.documentElement.clientWidth) {
68+
// Not enough space on the right, align to the right
69+
tooltip.style.right = '0px';
70+
}
6771
});
6872
});
6973

0 commit comments

Comments
 (0)