File tree Expand file tree Collapse file tree 3 files changed +34
-7
lines changed Expand file tree Collapse file tree 3 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import * as NavigationMenu from "@radix-ui/react-navigation-menu"
4
4
5
5
import { Button } from "@/components/Buttons"
6
6
7
- import { NAV_PY , SECTION_LABELS } from "@/lib/constants"
7
+ import { MAIN_NAV_ID , NAV_PY , SECTION_LABELS } from "@/lib/constants"
8
8
9
9
import type { NavSections } from "../types"
10
10
@@ -35,7 +35,12 @@ const Menu = ({ sections, ...props }: NavMenuProps) => {
35
35
delayDuration = { 0 }
36
36
>
37
37
< NavigationMenu . List asChild >
38
- < UnorderedList display = "flex" listStyleType = "none" m = "0" >
38
+ < UnorderedList
39
+ id = { MAIN_NAV_ID }
40
+ display = "flex"
41
+ listStyleType = "none"
42
+ m = "0"
43
+ >
39
44
{ SECTION_LABELS . map ( ( sectionKey ) => {
40
45
const { label, items } = sections [ sectionKey ]
41
46
const isActive = activeSection === sectionKey
Original file line number Diff line number Diff line change 1
1
import { useState } from "react"
2
2
import type { MotionProps } from "framer-motion"
3
+ import { useEventListener } from "@chakra-ui/react"
4
+
5
+ import { MAIN_NAV_ID , SECTION_LABELS } from "@/lib/constants"
3
6
4
7
import type { NavSectionKey , NavSections } from "../types"
5
8
@@ -11,6 +14,25 @@ export const useNavMenu = (sections: NavSections) => {
11
14
const menuColors = useNavMenuColors ( )
12
15
const [ activeSection , setActiveSection ] = useState < NavSectionKey | null > ( null )
13
16
17
+ // Focus corresponding nav section when number keys pressed
18
+ useEventListener ( "keydown" , ( event ) => {
19
+ if ( ! document || ! event . key . match ( / [ 1 - 9 ] / ) ) return
20
+ if ( event . target instanceof HTMLInputElement ) return
21
+ if ( event . target instanceof HTMLTextAreaElement ) return
22
+ if ( event . target instanceof HTMLSelectElement ) return
23
+
24
+ const sectionIdx = parseInt ( event . key ) - 1
25
+ if ( sectionIdx >= SECTION_LABELS . length ) return
26
+
27
+ const button = document . querySelector (
28
+ `#${ MAIN_NAV_ID } li:nth-of-type(${ sectionIdx + 1 } ) button`
29
+ )
30
+ if ( ! button ) return
31
+
32
+ event . preventDefault ( )
33
+ ; ( button as HTMLButtonElement ) . focus ( )
34
+ } )
35
+
14
36
const getEnglishSectionName = (
15
37
activeSection : string
16
38
) : NavSectionKey | null => {
Original file line number Diff line number Diff line change @@ -72,9 +72,6 @@ export const RANGES = ["30d", "90d"] as const
72
72
export const BEACONCHA_IN_URL = "https://beaconcha.in/"
73
73
export const ETHERSCAN_API_URL = "https://api.etherscan.io"
74
74
75
- export const NAV_BAR_PX_HEIGHT = "75px"
76
- export const FROM_QUERY = "from"
77
-
78
75
// Wallets
79
76
export const NUMBER_OF_SUPPORTED_LANGUAGES_SHOWN = 5
80
77
@@ -130,6 +127,11 @@ export const DEVELOPER_FEATURES = [
130
127
* Navigation
131
128
*/
132
129
130
+ export const MAIN_NAV_ID = "main-navigation"
131
+ export const NAV_BAR_PX_HEIGHT = "75px"
132
+ export const FROM_QUERY = "from"
133
+ export const NAV_PY = 4
134
+
133
135
// Determines the order of sections in the menu
134
136
export const SECTION_LABELS : NavSectionKey [ ] = [
135
137
"learn" ,
@@ -141,5 +143,3 @@ export const SECTION_LABELS: NavSectionKey[] = [
141
143
142
144
// Glossary Definition Component
143
145
export const DEFAULT_GLOSSARY_NS = "glossary"
144
-
145
- export const NAV_PY = 4
You can’t perform that action at this time.
0 commit comments