File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import CIcon from '@coreui/icons-react'
11
11
import { useLocation } from 'react-router-dom'
12
12
13
13
import { Context } from './CSidebar'
14
+ export const DropdownContext = React . createContext ( { } )
14
15
15
16
export const iconProps = ( icon ) => {
16
17
if ( typeof icon === 'object' ) {
@@ -100,13 +101,20 @@ const CSidebarNavDropdown = props => {
100
101
{ ...attributes }
101
102
ref = { ref }
102
103
>
103
- < a className = "c-sidebar-nav-dropdown-toggle" onClick = { toggle } >
104
+ < a
105
+ className = "c-sidebar-nav-dropdown-toggle"
106
+ tabIndex = "0"
107
+ onClick = { toggle }
108
+ aria-label = "menu dropdown"
109
+ >
104
110
{ icon && ( isValidElement ( icon ) ? icon : < CIcon { ...iconProps ( icon ) } /> ) }
105
111
{ fontIcon && < i className = { iconClasses } /> }
106
112
{ name }
107
113
</ a >
108
114
< ul className = "c-sidebar-nav-dropdown-items" >
109
- { children }
115
+ < DropdownContext . Provider value = { { isOpen } } >
116
+ { children }
117
+ </ DropdownContext . Provider >
110
118
</ ul >
111
119
</ li >
112
120
)
Original file line number Diff line number Diff line change 1
- import React , { isValidElement } from 'react'
1
+ import React , { isValidElement , useContext } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import classNames from 'classnames'
4
4
import { CLink , CBadge } from '../index'
5
5
import CIcon from '@coreui/icons-react'
6
6
import { iconProps } from './CSidebarNavDropdown'
7
7
8
+ import { DropdownContext } from './CSidebarNavDropdown'
9
+
8
10
//component - CoreUI / CSidebarNavItem
9
11
const CSidebarNavItem = props => {
10
12
@@ -23,7 +25,7 @@ const CSidebarNavItem = props => {
23
25
...rest
24
26
} = props
25
27
26
- //render
28
+ const { isOpen } = useContext ( DropdownContext )
27
29
const classes = classNames (
28
30
'c-sidebar-nav-item' ,
29
31
className
@@ -43,6 +45,7 @@ const CSidebarNavItem = props => {
43
45
className = { linkClasses }
44
46
{ ...routerLinkProps }
45
47
{ ...rest }
48
+ tabIndex = { isOpen === false ? - 1 : 0 }
46
49
>
47
50
{ icon && ( isValidElement ( icon ) ? icon : < CIcon { ...iconProps ( icon ) } /> ) }
48
51
{ fontIcon && < i className = { `c-sidebar-nav-icon ${ fontIcon } ` } /> }
You can’t perform that action at this time.
0 commit comments