@@ -40,6 +40,7 @@ export const FormInput = memo(function FormInput(
40
40
* Whether to include the field around the input. Defaults to false
41
41
*/
42
42
includeField ?: boolean
43
+ includeItem ?: boolean
43
44
} ,
44
45
) {
45
46
const absolutePath = useMemo ( ( ) => {
@@ -101,6 +102,34 @@ const FormInputInner = memo(function FormInputInner(
101
102
102
103
const { t} = useTranslation ( )
103
104
105
+ const renderField : RenderFieldCallback = useCallback (
106
+ ( fieldProps ) => {
107
+ // we want to render the field around the input if either of these are true:
108
+ // 1. we have reached the destination path and the `includeField`-prop is passed as true
109
+ // 2. we are currently at a node somewhere below/inside the destination path
110
+ const atDestination = isEqual ( absolutePath , fieldProps . path )
111
+ const shouldRenderField = atDestination
112
+ ? props . includeField
113
+ : startsWith ( absolutePath , fieldProps . path )
114
+ return shouldRenderField ? destinationRenderField ( fieldProps ) : pass ( fieldProps )
115
+ } ,
116
+ [ absolutePath , destinationRenderField , props . includeField ] ,
117
+ )
118
+
119
+ const renderItem : RenderArrayOfObjectsItemCallback = useCallback (
120
+ ( itemProps ) => {
121
+ // we want to render the item around the input if either of these are true:
122
+ // 1. we have reached the destination path and the `includeItem`-prop is passed as true
123
+ // 2. we are currently at a node somewhere below/inside the destination path
124
+ const atDestination = isEqual ( absolutePath , itemProps . path )
125
+ const shouldRenderItem = atDestination
126
+ ? props . includeItem
127
+ : startsWith ( absolutePath , itemProps . path )
128
+ return shouldRenderItem ? destinationRenderItem ( itemProps ) : pass ( itemProps )
129
+ } ,
130
+ [ absolutePath , destinationRenderItem , props . includeItem ] ,
131
+ )
132
+
104
133
const renderInput : RenderInputCallback = useCallback (
105
134
( inputProps ) => {
106
135
const isDestinationReached =
@@ -120,6 +149,8 @@ const FormInputInner = memo(function FormInputInner(
120
149
return (
121
150
< FormInputInner
122
151
{ ...inputProps }
152
+ includeField = { props . includeField }
153
+ includeItem = { props . includeItem }
123
154
absolutePath = { absolutePath }
124
155
destinationRenderAnnotation = { destinationRenderAnnotation }
125
156
destinationRenderBlock = { destinationRenderBlock }
@@ -140,35 +171,11 @@ const FormInputInner = memo(function FormInputInner(
140
171
destinationRenderInput ,
141
172
destinationRenderItem ,
142
173
destinationRenderPreview ,
174
+ props . includeField ,
175
+ props . includeItem ,
143
176
] ,
144
177
)
145
178
146
- const renderField : RenderFieldCallback = useCallback (
147
- ( fieldProps ) => {
148
- // we want to render the field around the input if either of these are true:
149
- // 1. we have reached the destination path and the `includeField`-prop is passed as true
150
- // 2. we are currently at a node somewhere below/inside the destination path
151
- const shouldRenderField =
152
- startsWith ( absolutePath , fieldProps . path ) &&
153
- ( props . includeField || ! isEqual ( absolutePath , fieldProps . path ) )
154
- return shouldRenderField ? destinationRenderField ( fieldProps ) : pass ( fieldProps )
155
- } ,
156
- [ absolutePath , destinationRenderField , props . includeField ] ,
157
- )
158
-
159
- const renderItem : RenderArrayOfObjectsItemCallback = useCallback (
160
- ( itemProps ) => {
161
- // we want to render the item around the input if either of these are true:
162
- // 1. we have reached the destination path and the `includeItem`-prop is passed as true
163
- // 2. we are currently at a node somewhere below/inside the destination path
164
- const shouldRenderField =
165
- startsWith ( absolutePath , itemProps . path ) &&
166
- ( props . includeItem || ! isEqual ( absolutePath , itemProps . path ) )
167
- return shouldRenderField ? destinationRenderItem ( itemProps ) : pass ( itemProps )
168
- } ,
169
- [ absolutePath , destinationRenderItem , props . includeItem ] ,
170
- )
171
-
172
179
const renderBlock : RenderBlockCallback = useCallback (
173
180
( blockProps ) => {
174
181
const shouldRenderBlock =
0 commit comments