From f4f794bc703d6ac2f075d07242493086d472a3d4 Mon Sep 17 00:00:00 2001 From: matttdawson <89495499+matttdawson@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:41:21 +1300 Subject: [PATCH] fix: Export all types from react menu, fix: MenuHeader not having children property (#51) * fix: Use correct types for anchor ref * Fix menu header missing children * Export react-menu types * fix: child type in MenuHeader * Removed proptypes --- index.ts | 7 ++++--- package-lock.json | 1 - package.json | 1 - src/react-menu3/components/ControlledMenu.tsx | 2 +- src/react-menu3/components/MenuHeader.tsx | 7 +++++-- src/react-menu3/positionUtils/positionMenu.ts | 2 +- src/react-menu3/types.ts | 10 +++++++++- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index ddff18e1..de2954f7 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,6 @@ +export * from "./src/react-menu3/index"; +export * from "./src/react-menu3/types"; + export { UpdatingContext } from "./src/contexts/UpdatingContext"; export { UpdatingContextProvider } from "./src/contexts/UpdatingContextProvider"; export { GridContext } from "./src/contexts/GridContext"; @@ -37,9 +40,7 @@ export { GridFormTextInput } from "./src/components/gridForm/GridFormTextInput"; export { TextAreaInput } from "./src/lui/TextAreaInput"; export { TextInputFormatted } from "./src/lui/TextInputFormatted"; -export { GridSubComponentTextArea } from "./src/components/GridSubComponentTextArea" +export { GridSubComponentTextArea } from "./src/components/GridSubComponentTextArea"; export * from "./src/utils/bearing"; export * from "./src/utils/util"; - -export * from "./src/react-menu3/index"; diff --git a/package-lock.json b/package-lock.json index 2bf58c0d..6aa4aca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "ag-grid-react": ">=27", "debounce-promise": "^3.1.2", "lodash-es": "^4.17.21", - "prop-types": "^15.8.1", "react": ">=17", "react-dom": ">=17", "react-transition-state": "^1.1.5", diff --git a/package.json b/package.json index 5758a764..b17da700 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "ag-grid-react": ">=27", "debounce-promise": "^3.1.2", "lodash-es": "^4.17.21", - "prop-types": "^15.8.1", "react": ">=17", "react-dom": ">=17", "react-transition-state": "^1.1.5", diff --git a/src/react-menu3/components/ControlledMenu.tsx b/src/react-menu3/components/ControlledMenu.tsx index f9976ee9..314c7130 100644 --- a/src/react-menu3/components/ControlledMenu.tsx +++ b/src/react-menu3/components/ControlledMenu.tsx @@ -236,7 +236,7 @@ export const ControlledMenuFr = ( ); - if (portal === true && anchorRef?.current !== undefined) { + if (portal === true && anchorRef?.current != null) { portal = { target: anchorRef.current.ownerDocument.body } as PortalFieldType; } diff --git a/src/react-menu3/components/MenuHeader.tsx b/src/react-menu3/components/MenuHeader.tsx index 74627715..be2b77f1 100644 --- a/src/react-menu3/components/MenuHeader.tsx +++ b/src/react-menu3/components/MenuHeader.tsx @@ -1,9 +1,12 @@ import { memo, forwardRef, ForwardedRef } from "react"; import { useBEM } from "../hooks"; import { menuClass, menuHeaderClass } from "../utils"; -import { BaseProps } from "../types"; +import { BasePropsWithChildren } from "../types"; -export const MenuHeaderFr = ({ className, ...restProps }: BaseProps, externalRef: ForwardedRef) => { +export const MenuHeaderFr = ( + { className, ...restProps }: BasePropsWithChildren, + externalRef: ForwardedRef, +) => { return (
  • ; - anchorRef: MutableRefObject; + anchorRef: MutableRefObject; arrow?: boolean; direction: MenuDirection; position: "auto" | "anchor" | "initial"; diff --git a/src/react-menu3/types.ts b/src/react-menu3/types.ts index b2024447..00ce9c92 100644 --- a/src/react-menu3/types.ts +++ b/src/react-menu3/types.ts @@ -31,6 +31,14 @@ export interface BaseProps extends Omit; } +export interface BasePropsWithChildren extends Omit, "className"> { + ref?: React.Ref; + /** + * Can be a string or a function which receives a modifier object and returns a CSS `class` string. + */ + className?: ClassNameProp; +} + export interface Event { /** * The `value` prop passed to the `MenuItem` being clicked. @@ -397,7 +405,7 @@ export interface ControlledMenuProps extends RootMenuProps, ExtraMenuProps { * * *Don't set this prop for context menu* */ - anchorRef?: React.MutableRefObject; + anchorRef?: React.RefObject; skipOpen?: React.MutableRefObject; /** * If `true`, the menu list element will gain focus after menu is open.