Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add: Focus the main page content on-load, navigation, and search
4 changes: 4 additions & 0 deletions znai-reactjs/src/layout/DocumentationLayout.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
-webkit-overflow-scrolling: touch;
}

.znai-main-panel:focus {
outline: none;
}

::-webkit-scrollbar {
width: var(--znai-scrollbar-width);
height: var(--znai-scrollbar-height);
Expand Down
11 changes: 9 additions & 2 deletions znai-reactjs/src/layout/DocumentationLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import React, { useState } from "react";
import React, { useState, useRef, useEffect } from "react";

import TocPanel from "./TocPanel";
import { PageGenError } from "../doc-elements/page-gen-error/PageGenError";
Expand Down Expand Up @@ -82,16 +82,23 @@ export function DocumentationLayout({
}: Props) {
const [isMobileTocVisible, setMobileTocVisible] = useState(false);
const isMobile = useIsMobile();
const pageContentRef = useRef<HTMLDivElement>(null);

const pageGenErrorPanel = pageGenError ? <PageGenError error={pageGenError} /> : null;

const panelFullClassName = mainPanelClassName + (isMobile ? " mobile" : "");

useEffect(() => {
if (pageContentRef.current) {
pageContentRef.current.focus();
}
}, [selectedTocItem]);

return isMobile ? renderMobile() : renderDesktop();

function renderPageContent() {
return (
<div className={panelFullClassName}>
<div ref={pageContentRef} className={panelFullClassName} tabIndex={1}>
{renderedPage}

<div className="page-bottom">
Expand Down