File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
packages/main/src/components Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ const component = (
24
24
< Input data-testid = "formInput2" type = { InputType . Text } />
25
25
</ FormItem >
26
26
< FormItem label = { < Label > item 4</ Label > } >
27
- < Input type = { InputType . Number } />
27
+ < Input type = { InputType . Number } id = "test-id" />
28
28
</ FormItem >
29
29
</ FormGroup >
30
30
</ Form >
@@ -81,6 +81,10 @@ describe('Form', () => {
81
81
// custom `Label`
82
82
cy . findAllByText ( `item 4` ) . eq ( 0 ) . should ( 'be.visible' ) ;
83
83
cy . findAllByText ( `item 4` ) . eq ( 1 ) . should ( 'exist' ) . should ( 'not.be.visible' ) ;
84
+
85
+ // custom id child of FormItem
86
+ cy . get ( '#test-id' ) . should ( 'have.length' , 1 ) . should ( 'be.visible' ) ;
87
+ cy . get ( '[for="test-id"]' ) . should ( 'have.length' , 1 ) . should ( 'not.be.visible' ) ;
84
88
} ) ;
85
89
86
90
it ( 'FilterItem: doesnt crash with portal as child' , ( ) => {
Original file line number Diff line number Diff line change @@ -156,11 +156,12 @@ const FormItem = (props: FormItemPropTypes) => {
156
156
// @ts -expect-error: type can't be string because of `isValidElement`
157
157
if ( isValidElement ( child ) && child . type && child . type . $$typeof !== Symbol . for ( 'react.portal' ) ) {
158
158
const content = getContentForHtmlLabel ( label ) ;
159
+ const childId = child ?. props ?. id ;
159
160
return (
160
161
< Fragment key = { `${ content } -${ uniqueId } ` } >
161
162
{ /*@ts -expect-error: child is ReactElement*/ }
162
- { cloneElement ( child , { id : `${ uniqueId } -${ index } ` } ) }
163
- < label htmlFor = { `${ uniqueId } -${ index } ` } style = { { display : 'none' } } aria-hidden = { true } >
163
+ { cloneElement ( child , { id : childId ?? `${ uniqueId } -${ index } ` } ) }
164
+ < label htmlFor = { childId ?? `${ uniqueId } -${ index } ` } style = { { display : 'none' } } aria-hidden = { true } >
164
165
{ content }
165
166
</ label >
166
167
</ Fragment >
You can’t perform that action at this time.
0 commit comments