MCPcopy Create free account
hub / github.com/DavidWells/analytics / SelectLink

Function SelectLink

site/gatsby-theme-oss-docs/src/components/select-link.js:6–44  ·  view source on GitHub ↗
({options, useLink, isPathActive, ...props})

Source from the content-addressed store, hash-verified

4import {navigate, withPrefix} from 'gatsby'
5
6export default function SelectLink({options, useLink, isPathActive, ...props}) {
7 function handleChange(event) {
8 if (useLink) {
9 navigate(event.target.value)
10 return
11 }
12
13 window.location.href = event.target.value
14 }
15
16 let value
17 options.forEach(option => {
18 const path = useLink ? withPrefix(option.value) : option.value
19 const isActive = option.matchRegex
20 ? option.matchRegex.test(path)
21 : isPathActive(path)
22 if (isActive) {
23 value = option.value
24 }
25
26 if (option.subpages) {
27 option.subpages.forEach(subpage => {
28 if (isPathActive(subpage.value)) {
29 value = option.value
30 }
31 })
32 }
33 })
34
35 return (
36 <Select {...props} value={value} onChange={handleChange}>
37 {options.map(option => (
38 <option key={option.value} value={option.value}>
39 {option.text}
40 </option>
41 ))}
42 </Select>
43 )
44}
45
46SelectLink.propTypes = {
47 options: PropTypes.array.isRequired,

Callers

nothing calls this directly

Calls 1

isPathActiveFunction · 0.85

Tested by

no test coverage detected