Skip to content

Commit

Permalink
Prevent the route announcer from being visible (#8977)
Browse files Browse the repository at this point in the history
* Prevent the route announcer from being visible

* Update the number of expected styles in the tests
  • Loading branch information
matthewp authored and natemoo-re committed Nov 22, 2023
1 parent 20a36ad commit 89854b6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-ads-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevent route announcer from being visible
17 changes: 15 additions & 2 deletions packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ export interface Props {
fallback?: Fallback;
}
const { fallback = 'animate' } = Astro.props as Props;
const { fallback = 'animate' } = Astro.props;
---

<style is:global>
/* Route announcer */
.astro-route-announcer {
position: absolute;
left: 0;
top: 0;
clip: rect(0 0 0 0);
clip-path: inset(50%);
overflow: hidden;
white-space: nowrap;
width: 1px;
height: 1px;
}
</style>
<meta name="astro-view-transitions-enabled" content="true" />
<meta name="astro-view-transitions-fallback" content={fallback} />
<script>
Expand Down
13 changes: 0 additions & 13 deletions packages/astro/components/viewtransitions.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,3 @@
animation: none !important;
}
}

/* Route announcer */
.astro-route-announcer {
position: absolute;
left: 0;
top: 0;
clip: rect(0 0 0 0);
clip-path: inset(50%);
overflow: hidden;
white-space: nowrap;
width: 1px;
height: 1px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
import { ViewTransitions } from 'astro:transitions';
---
<html>
<head>
<title>Testing</title>
<ViewTransitions />
</head>
<body>
<p id="one">One</p>
<a href="/no-directive-two">Go to 2</a>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
import { ViewTransitions } from 'astro:transitions';
---
<html>
<head>
<title>Testing</title>
<ViewTransitions />
</head>
<body>
<p id="two">Two</p>
</body>
</html>
20 changes: 17 additions & 3 deletions packages/astro/e2e/view-transitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ test.describe('View Transitions', () => {
});

test('client:only styles are retained on transition (1/2)', async ({ page, astro }) => {
const totalExpectedStyles = 8;
const totalExpectedStyles = 9;

await page.goto(astro.resolveUrl('/client-only-one'));
let msg = page.locator('.counter-message');
Expand All @@ -703,8 +703,8 @@ test.describe('View Transitions', () => {
});

test('client:only styles are retained on transition (2/2)', async ({ page, astro }) => {
const totalExpectedStyles_page_three = 10;
const totalExpectedStyles_page_four = 8;
const totalExpectedStyles_page_three = 11;
const totalExpectedStyles_page_four = 9;

await page.goto(astro.resolveUrl('/client-only-three'));
let msg = page.locator('#name');
Expand Down Expand Up @@ -887,4 +887,18 @@ test.describe('View Transitions', () => {
await locator.type(' World');
await expect(locator).toHaveValue('Hello World');
});

test('Route announcer is invisible on page transition', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/no-directive-one'));

let locator = page.locator('#one');
await expect(locator, 'should have content').toHaveText('One');

await page.click('a');
locator = page.locator('#two');
await expect(locator, 'should have content').toHaveText('Two');

let announcer = page.locator('.astro-route-announcer');
await expect(announcer, 'should have content').toHaveCSS('width', '1px');
});
});

0 comments on commit 89854b6

Please sign in to comment.