|
1 | 1 | import styled from 'styled-components' |
2 | | -import { NavLink } from 'react-router-dom' |
| 2 | +import { NavLink, useLocation } from 'react-router-dom' |
3 | 3 | import { useState, useEffect } from 'react'; |
4 | 4 |
|
5 | 5 | const SidebarContainer = styled.div<{ $isExpanded: boolean }>` |
@@ -62,6 +62,7 @@ export const Sidebar = () => { |
62 | 62 | const [focusedIndex, setFocusedIndex] = useState(-1); |
63 | 63 | const [isExpanded, setIsExpanded] = useState(false); |
64 | 64 | const [isMobile, setIsMobile] = useState(window.innerWidth < 768); |
| 65 | + const location = useLocation(); |
65 | 66 |
|
66 | 67 | // Helper function to determine shortcut keys |
67 | 68 | const determineShortcutKeys = (items: { to: string; label: string }[]): NavItemType[] => { |
@@ -101,6 +102,8 @@ export const Sidebar = () => { |
101 | 102 |
|
102 | 103 | // Add mobile detection |
103 | 104 | useEffect(() => { |
| 105 | + setFocusedIndex(baseNavItems.findIndex(item => item.to === location.pathname)); |
| 106 | + |
104 | 107 | const handleResize = () => { |
105 | 108 | setIsMobile(window.innerWidth < 768); |
106 | 109 | if (window.innerWidth >= 768) { |
@@ -148,7 +151,7 @@ export const Sidebar = () => { |
148 | 151 |
|
149 | 152 | const renderLabel = (label: string, shortcutKey: string) => { |
150 | 153 | const index = label.toLowerCase().indexOf(shortcutKey); |
151 | | - if (index === -1) return label; |
| 154 | + if (index === -1 || isMobile) return label; |
152 | 155 |
|
153 | 156 | return ( |
154 | 157 | <> |
|
0 commit comments