Rocky_Mountain_Vending/.pnpm-store/v10/files/31/97d6788cf95e3128f28873844fcd523db03935cb7135a7618100c4118560147c7137c284050613c3cc58dc9cbadfbd14b3e8763d555309ea81ed70cd047bc9
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

56 lines
No EOL
2.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { useRouter } from './router';
const nextjsRouteAnnouncerStyles = {
border: 0,
clip: 'rect(0 0 0 0)',
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: 0,
position: 'absolute',
top: 0,
width: '1px',
// https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
whiteSpace: 'nowrap',
wordWrap: 'normal'
};
export const RouteAnnouncer = ()=>{
const { asPath } = useRouter();
const [routeAnnouncement, setRouteAnnouncement] = React.useState('');
// Only announce the path change, but not for the first load because screen
// reader will do that automatically.
const previouslyLoadedPath = React.useRef(asPath);
// Every time the path changes, announce the new pages title following this
// priority: first the document title (from head), otherwise the first h1, or
// if none of these exist, then the pathname from the URL. This methodology is
// inspired by Marcy Suttons accessible client routing user testing. More
// information can be found here:
// https://www.gatsbyjs.com/blog/2019-07-11-user-testing-accessible-client-routing/
React.useEffect(()=>{
// If the path hasn't change, we do nothing.
if (previouslyLoadedPath.current === asPath) return;
previouslyLoadedPath.current = asPath;
if (document.title) {
setRouteAnnouncement(document.title);
} else {
const pageHeader = document.querySelector('h1');
const content = pageHeader?.innerText ?? pageHeader?.textContent;
setRouteAnnouncement(content || asPath);
}
}, // TODO: switch to pathname + query object of dynamic route requirements
[
asPath
]);
return /*#__PURE__*/ _jsx("p", {
"aria-live": "assertive" // Make the announcement immediately.
,
id: "__next-route-announcer__",
role: "alert",
style: nextjsRouteAnnouncerStyles,
children: routeAnnouncement
});
};
export default RouteAnnouncer;
//# sourceMappingURL=route-announcer.js.map