diff --git a/package-lock.json b/package-lock.json index de8c08c9..2981c0f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3453,6 +3453,11 @@ "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.7.tgz", "integrity": "sha512-X8R8Oj771YRl/w+c1HqAC1szL8zWQRwFvgDwT129k9ACdBoud/+/rX9V0qiMl6LWUdP9voC2nDVZYPMQQsb6eA==" }, + "node_modules/@formkit/auto-animate": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/@formkit/auto-animate/-/auto-animate-0.8.2.tgz", + "integrity": "sha512-SwPWfeRa5veb1hOIBMdzI+73te5puUBHmqqaF1Bu7FjvxlYSz/kJcZKSa9Cg60zL0uRNeJL2SbRxV6Jp6Q1nFQ==" + }, "node_modules/@hapi/hoek": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", @@ -36084,6 +36089,7 @@ "version": "0.15.0", "license": "LGPL-3.0", "dependencies": { + "@formkit/auto-animate": "^0.8.2", "@hookform/error-message": "^2.0.1", "@mantine/carousel": "^7.11.0", "@mantine/charts": "^7.11.0", diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZone.tsx b/packages/haring-react/src/Form/DynamicZone/DynamicZone.tsx index 5845e30d..2b4b3f9f 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZone.tsx +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZone.tsx @@ -11,7 +11,7 @@ import type { StackProps, TextProps, } from '@mantine/core'; -import type { ReactElement } from 'react'; +import type { ReactElement, Ref } from 'react'; import { Button, Container, Group, Stack, Text, Tooltip } from '@mantine/core'; @@ -19,6 +19,7 @@ import classes from './DynamicZone.module.css'; import { DynamicZoneBlock } from './DynamicZoneBlock/DynamicZoneBlock'; export interface IDynamicZoneInternalComponentProps { + arrayRootRef?: Ref; blockCardProps?: CardProps; blocksStackProps?: StackProps; bottomContainerProps?: ContainerProps; @@ -60,7 +61,11 @@ export function DynamicZone(props: IDynamicZoneProps): ReactElement { return ( - + {blocks.map((block, index) => ( = (data) => onFormSubmit(data); const onInvalidSubmit: SubmitErrorHandler = (errors) => onFormErrors(errors); @@ -206,6 +209,9 @@ export function ReactHookFormDynamicZone( availableBlocks={availableBlock(register, errors)} blocksArray={fields} + internalDynamicZoneProps={{ + internalComponentProps: { arrayRootRef: parent }, + }} onAppendUpdate={(newBlock: IDynamicContents) => append(newBlock)} onRemoveUpdate={(i: number) => remove(i)} onSwapUpdate={(i: number, ii: number) => swap(i, ii)}