diff --git a/src/components/ActionControl/ActionControl.tsx b/src/components/ActionControl/ActionControl.tsx index 278c050c..99f93778 100644 --- a/src/components/ActionControl/ActionControl.tsx +++ b/src/components/ActionControl/ActionControl.tsx @@ -15,10 +15,11 @@ limitations under the License. */ import classnames from "classnames"; -import React, { PropsWithChildren, useId, forwardRef } from "react"; +import React, { PropsWithChildren, forwardRef } from "react"; import styles from "./ActionControl.module.css"; import { Control, Field, Root } from "../Form"; +import useId from "../../utils/useId"; type ActionControlProps = { /** diff --git a/src/utils/useId.ts b/src/utils/useId.ts new file mode 100644 index 00000000..4c9cde6d --- /dev/null +++ b/src/utils/useId.ts @@ -0,0 +1,16 @@ +import * as React from "react"; + +const react18UseId = (React as { useId?: () => string }).useId; + +const getUniqueId = (() => { + let index = 1; + return () => `:r${index++}:`; +})(); + +const useIdPonyFill = (): string => { + return React.useMemo(getUniqueId, []); +}; + +const useId = typeof react18UseId === "function" ? react18UseId : useIdPonyFill; + +export default useId;