diff --git a/.changeset/eight-insects-tan.md b/.changeset/eight-insects-tan.md index d9bb899225..13a53b227a 100644 --- a/.changeset/eight-insects-tan.md +++ b/.changeset/eight-insects-tan.md @@ -2,4 +2,5 @@ '@backstage/core-components': patch --- -Add `useContent` hook to have a reference to the current main content element +- Add `useContent` hook to have a reference to the current main content element +- Sets the main content reference on `Content` component diff --git a/.changeset/eleven-sloths-shake.md b/.changeset/eleven-sloths-shake.md new file mode 100644 index 0000000000..64602b561d --- /dev/null +++ b/.changeset/eleven-sloths-shake.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search': patch +--- + +Removes the focus from the sidebar and focus the main content after select one search result or navigate to the search result list diff --git a/packages/core-components/src/layout/Sidebar/Page.tsx b/packages/core-components/src/layout/Sidebar/Page.tsx index 00377d8786..2a851b0a5c 100644 --- a/packages/core-components/src/layout/Sidebar/Page.tsx +++ b/packages/core-components/src/layout/Sidebar/Page.tsx @@ -147,6 +147,25 @@ export function SidebarPage(props: SidebarPageProps) { ); } +/** + * This hook provides a react ref to the main content. + * Allows to set an element as the main content and focus on that component. + * + * *Note: If `contentRef` is not set `focusContent` is noop. `Content` component sets this ref automaticaly* + * + * @public + * @example + * const { focusContent} = useContent(); + * ... + * + * + * @example + * const { contentRef } = useContent(); + * ... + *
Main Content
+ */ export function useContent() { const { content } = useContext(PageContext);