diff --git a/.changeset/open-lands-shop.md b/.changeset/open-lands-shop.md new file mode 100644 index 0000000000..5205e83cbe --- /dev/null +++ b/.changeset/open-lands-shop.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Update keyboard focus on when clicking hash links. This fixes the issue where the "skip to content" link rendered by Material MkDocs isn't focused when used. diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx index c17d5fcac4..9dbb9745d3 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx @@ -229,6 +229,13 @@ export const useTechDocsReaderDom = ( transformedElement ?.querySelector(`[id="${parsedUrl.hash.slice(1)}"]`) ?.scrollIntoView(); + + // Focus first focusable element in the target section + ( + transformedElement + ?.querySelector(`[id="${parsedUrl.hash.slice(1)}"]`) + ?.querySelector('a, button, [tabindex]') as HTMLElement + )?.focus(); } } else { if (modifierActive) {