Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Set focus to skip link target to improve screen reader announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
andymantell committed Jan 29, 2022
1 parent 7174941 commit 5a7263f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/govuk/components/skip-link/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import React from 'react';
import React, { useEffect } from 'react';

function SkipLink(props) {
const { href, className, children, ...attributes } = props;

const skipLinkRef = React.createRef();

useEffect(() => {
(async () => {
if (typeof document !== 'undefined') {
const { default: SkipLinkJS } = await import(
/* webpackChunkName: "govuk-frontend-skip-link" */
/* webpackMode: "lazy" */
/* webpackPrefetch: true */
'govuk-frontend/govuk/components/skip-link/skip-link'
);

if (skipLinkRef.current) {
new SkipLinkJS(skipLinkRef.current).init();
}
}
})();
}, [skipLinkRef]);

return (
<a
href={href}
className={`govuk-skip-link ${className || ''}`}
data-module="govuk-skip-link"
ref={skipLinkRef}
{...attributes}
>
{children}
Expand Down

0 comments on commit 5a7263f

Please sign in to comment.