Skip to content

Commit d9ef058

Browse files
ux: auto focus page content (#1335)
1 parent 2009fab commit d9ef058

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add: Focus the main page content on-load, navigation, and search

znai-reactjs/src/layout/DocumentationLayout.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
-webkit-overflow-scrolling: touch;
5353
}
5454

55+
.znai-main-panel:focus {
56+
outline: none;
57+
}
58+
5559
::-webkit-scrollbar {
5660
width: var(--znai-scrollbar-width);
5761
height: var(--znai-scrollbar-height);

znai-reactjs/src/layout/DocumentationLayout.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useState } from "react";
17+
import React, { useState, useRef, useEffect } from "react";
1818

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

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

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

91+
useEffect(() => {
92+
if (pageContentRef.current) {
93+
pageContentRef.current.focus();
94+
}
95+
}, [selectedTocItem]);
96+
9097
return isMobile ? renderMobile() : renderDesktop();
9198

9299
function renderPageContent() {
93100
return (
94-
<div className={panelFullClassName}>
101+
<div ref={pageContentRef} className={panelFullClassName} tabIndex={1}>
95102
{renderedPage}
96103

97104
<div className="page-bottom">

0 commit comments

Comments
 (0)