ContextMenu: make focus on open optional (#45170)

This commit is contained in:
Ryan McKinley
2022-02-09 11:43:08 -08:00
committed by GitHub
parent 10232c7857
commit 1bdbc3abdf
2 changed files with 10 additions and 3 deletions

View File

@@ -6,9 +6,11 @@ interface WithContextMenuProps {
children: (props: { openMenu: React.MouseEventHandler<HTMLElement> }) => JSX.Element;
/** A function that returns an array of menu items */
renderMenuItems: () => React.ReactNode;
/** On menu open focus the first element */
focusOnOpen?: boolean;
}
export const WithContextMenu: React.FC<WithContextMenuProps> = ({ children, renderMenuItems }) => {
export const WithContextMenu: React.FC<WithContextMenuProps> = ({ children, renderMenuItems, focusOnOpen = true }) => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 });
return (
@@ -29,6 +31,7 @@ export const WithContextMenu: React.FC<WithContextMenuProps> = ({ children, rend
x={menuPosition.x}
y={menuPosition.y}
renderMenuItems={renderMenuItems}
focusOnOpen={focusOnOpen}
/>
)}
</>