|
1 | | -import PropTypes from 'prop-types'; |
2 | 1 | import React, { useEffect, useContext, useRef } from 'react'; |
3 | 2 | import { MenubarContext, SubmenuContext, ParentMenuContext } from './contexts'; |
4 | | -import { ButtonOrLink } from '../../common/ButtonOrLink'; |
| 3 | +import { ButtonOrLink, ButtonOrLinkProps } from '../../common/ButtonOrLink'; |
| 4 | + |
| 5 | +export enum MenubarItemRole { |
| 6 | + MENU_ITEM = 'menuitem', |
| 7 | + OPTION = 'option' |
| 8 | +} |
| 9 | + |
| 10 | +export interface MenubarItemProps extends Omit<ButtonOrLinkProps, 'role'> { |
| 11 | + /** |
| 12 | + * Provides a way to deal with optional items. |
| 13 | + */ |
| 14 | + role?: MenubarItemRole; |
| 15 | + selected?: boolean; |
| 16 | +} |
5 | 17 |
|
6 | 18 | /** |
7 | 19 | * MenubarItem wraps a button or link in an accessible list item that |
@@ -36,14 +48,14 @@ import { ButtonOrLink } from '../../common/ButtonOrLink'; |
36 | 48 | * </MenubarItem> |
37 | 49 | */ |
38 | 50 |
|
39 | | -function MenubarItem({ |
40 | | - className, |
| 51 | +export function MenubarItem({ |
| 52 | + className = 'nav__dropdown-item', |
41 | 53 | id, |
42 | | - role: customRole, |
43 | | - isDisabled, |
44 | | - selected, |
| 54 | + role: customRole = MenubarItemRole.MENU_ITEM, |
| 55 | + isDisabled = false, |
| 56 | + selected = false, |
45 | 57 | ...rest |
46 | | -}) { |
| 58 | +}: MenubarItemProps) { |
47 | 59 | const { createMenuItemHandlers, hasFocus } = useContext(MenubarContext); |
48 | 60 | const { |
49 | 61 | setSubmenuActiveIndex, |
@@ -94,25 +106,3 @@ function MenubarItem({ |
94 | 106 | </li> |
95 | 107 | ); |
96 | 108 | } |
97 | | - |
98 | | -MenubarItem.propTypes = { |
99 | | - ...ButtonOrLink.propTypes, |
100 | | - className: PropTypes.string, |
101 | | - id: PropTypes.string, |
102 | | - /** |
103 | | - * Provides a way to deal with optional items. |
104 | | - */ |
105 | | - role: PropTypes.oneOf(['menuitem', 'option']), |
106 | | - isDisabled: PropTypes.bool, |
107 | | - selected: PropTypes.bool |
108 | | -}; |
109 | | - |
110 | | -MenubarItem.defaultProps = { |
111 | | - className: 'nav__dropdown-item', |
112 | | - id: undefined, |
113 | | - role: 'menuitem', |
114 | | - isDisabled: false, |
115 | | - selected: false |
116 | | -}; |
117 | | - |
118 | | -export default MenubarItem; |
0 commit comments