File tree Expand file tree Collapse file tree 1 file changed +22
-18
lines changed Expand file tree Collapse file tree 1 file changed +22
-18
lines changed Original file line number Diff line number Diff line change 66 * Copyright Oxide Computer Company
77 */
88import cn from 'classnames'
9- import { NavLink } from 'react-router-dom'
9+ import { NavLink , useLocation } from 'react-router-dom'
1010
1111import { Action16Icon , Document16Icon } from '@oxide/design-system/icons/react'
1212
@@ -88,20 +88,24 @@ export const NavLinkItem = (props: {
8888 children : React . ReactNode
8989 end ?: boolean
9090 disabled ?: boolean
91- } ) => (
92- < li >
93- < NavLink
94- to = { props . to }
95- className = { ( { isActive } ) =>
96- cn ( linkStyles , {
97- 'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary' :
98- isActive ,
99- 'pointer-events-none text-disabled' : props . disabled ,
100- } )
101- }
102- end = { props . end }
103- >
104- { props . children }
105- </ NavLink >
106- </ li >
107- )
91+ } ) => {
92+ // If the current page is the create form for this NavLinkItem's resource, highlight the NavLink in the sidebar
93+ const currentPathIsCreateForm = useLocation ( ) . pathname . startsWith ( `${ props . to } -new` )
94+ return (
95+ < li >
96+ < NavLink
97+ to = { props . to }
98+ className = { ( { isActive } ) =>
99+ cn ( linkStyles , {
100+ 'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary' :
101+ isActive || currentPathIsCreateForm ,
102+ 'pointer-events-none text-disabled' : props . disabled ,
103+ } )
104+ }
105+ end = { props . end }
106+ >
107+ { props . children }
108+ </ NavLink >
109+ </ li >
110+ )
111+ }
You can’t perform that action at this time.
0 commit comments