Skip to content

Commit 11fcf49

Browse files
committed
WIP fix type errors on MenubarSubmenu --no-verify
1 parent 50c2821 commit 11fcf49

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

client/components/Menubar/Menubar.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ import { usePrevious } from '../../common/usePrevious';
1212
import { KeydownHandlerMap } from '../../common/useKeyDownHandlers';
1313

1414
export interface MenubarProps {
15+
// Menu items that will be rendered in the menubar
1516
children?: React.ReactNode;
17+
// CSS class name to apply to the menubar
1618
className?: string;
1719
}
1820

1921
/**
2022
* Menubar manages a collection of menu items and their submenus. It provides keyboard navigation,
2123
* focus and state management, and other accessibility features for the menu items and submenus.
2224
*
23-
* @param {React.ReactNode} props.children - Menu items that will be rendered in the menubar
24-
* @param {string} [props.className='nav__menubar'] - CSS class name to apply to the menubar
25-
* @returns {JSX.Element}
26-
*
2725
* @example
2826
* <Menubar>
2927
* <MenubarSubmenu id="file" title="File">

client/components/Menubar/MenubarSubmenu.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ const MenubarTrigger = React.forwardRef<HTMLButtonElement, MenubarTriggerProps>(
8484
const handleMouseEnter = () => {
8585
if (hasFocus) {
8686
const items = Array.from(menuItems);
87-
const index = items.findIndex((item) => item === ref.current);
87+
const index = items.findIndex(
88+
(item) =>
89+
item ===
90+
(ref as React.MutableRefObject<HTMLButtonElement | null>).current
91+
);
8892

8993
if (index !== -1) {
9094
setActiveIndex(index);
@@ -228,7 +232,7 @@ export function MenubarSubmenu({
228232
const { isOpen, handlers } = useMenuProps(id);
229233
const [submenuActiveIndex, setSubmenuActiveIndex] = useState(0);
230234
const { setMenuOpen, toggleMenuOpen } = useContext(MenubarContext);
231-
const submenuItems = useRef(new Set()).current;
235+
const submenuItems = useRef<Set<HTMLElement>>(new Set()).current;
232236

233237
const buttonRef = useRef(null);
234238
const listItemRef = useRef(null);

client/components/Menubar/contexts.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ interface MenubarContextType {
1212

1313
// MenubarItem
1414
createMenuItemHandlers: (id: string) => Record<string, any>;
15-
hasFocus?: boolean;
15+
hasFocus: boolean;
1616

1717
// MenubarSubmenu
1818
setActiveIndex: (index: number) => void;
19-
menuItems: Set<HTMLElement>;
20-
registerTopLevelItem: (ref: unknown, id: string) => void;
19+
menuItems: Set<HTMLButtonElement>;
20+
registerTopLevelItem: (
21+
ref: React.Ref<HTMLButtonElement>,
22+
id: string
23+
) => () => void; // returns unregister fn
2124
}
2225

2326
export const MenubarContext = createContext<MenubarContextType>({
@@ -27,20 +30,18 @@ export const MenubarContext = createContext<MenubarContextType>({
2730
setMenuOpen: () => {},
2831
setActiveIndex: () => {},
2932
hasFocus: false,
30-
menuItems: Set<HTMLElement>,
31-
registerTopLevelItem(ref: unknown, id: string): void {
32-
throw new Error('Function not implemented.');
33-
}
33+
menuItems: new Set<HTMLButtonElement>(),
34+
registerTopLevelItem: () => () => {}
3435
});
3536

3637
interface SubmenuContextType {
37-
submenuItems: Set<HTMLElement>;
38+
submenuItems: Set<HTMLLIElement>;
3839
setSubmenuActiveIndex: (index: number) => void;
39-
registerSubmenuItem: (ref: React.RefObject<HTMLElement>) => () => void;
40+
registerSubmenuItem: (ref: React.Ref<HTMLLIElement>) => () => void;
4041
id: string;
4142
title: string;
42-
first: () => {};
43-
last: () => {};
43+
first: () => void;
44+
last: () => void;
4445
}
4546

4647
export const SubmenuContext = createContext<SubmenuContextType>({
@@ -49,10 +50,6 @@ export const SubmenuContext = createContext<SubmenuContextType>({
4950
registerSubmenuItem: () => () => {},
5051
id: '',
5152
title: '',
52-
first(): {} {
53-
throw new Error('Function not implemented.');
54-
},
55-
last(): {} {
56-
throw new Error('Function not implemented.');
57-
}
53+
first: () => {},
54+
last: () => {}
5855
});

0 commit comments

Comments
 (0)