Skip to content

Commit

Permalink
Passed focus to SideNavExpanded when opened
Browse files Browse the repository at this point in the history
  • Loading branch information
abottega committed Dec 28, 2023
1 parent a347b1b commit 20e19e3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/components/SideNav/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, { useRef, useState, useEffect } from "react";
import styled from "styled-components";
import { css } from "@styled-system/css";
import { themeGet } from "@styled-system/theme-get";
Expand Down Expand Up @@ -500,6 +500,16 @@ const SideNav = ({ items, sideNavHeight }) => {
return () => window.removeEventListener("resize", debounceResize);
});

// Initialize a ref for SideNavExpanded
const expandedRef = useRef(null);

// Use a useEffect to focus on the expanded item
useEffect(() => {
if (expandedItem !== null && expandedRef.current) {
expandedRef.current.focus();
}
}, [expandedItem]);

// Toggle nav item names on click of panel control button
// const [showItemNames, setShowItemNames] = useState(false);
// const toggleItemNames = () => {
Expand Down Expand Up @@ -675,6 +685,7 @@ const SideNav = ({ items, sideNavHeight }) => {
<PanelControl
onClick={() => handleItemClick(allItems[expandedItem])}
aria-label="toggle panel"
ref={expandedRef}
>
{isGreaterThan900 === true ? (
<Icon icon={["fas", "chevron-left"]} />
Expand Down

0 comments on commit 20e19e3

Please sign in to comment.