Skip to content

Commit 3cf6431

Browse files
srotbartsrotbart123layershifter
authored
fix(FormFiled): pass id when contains child elements or has content prop (#3901)
* Fixed an issue where id was not set for FormField when content or child elements were provided * Update src/collections/Form/FormField.js * Update src/collections/Form/FormField.js * Update src/collections/Form/FormField.js Co-authored-by: srotbart <srotbart@ebay.com> Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
1 parent 83c2ce4 commit 3cf6431

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/collections/Form/FormField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ function FormField(props) {
7878
if (_.isNil(control)) {
7979
if (_.isNil(label)) {
8080
return (
81-
<ElementType {...rest} className={classes}>
81+
<ElementType {...rest} className={classes} id={id}>
8282
{childrenUtils.isNil(children) ? content : children}
8383
</ElementType>
8484
)
8585
}
8686

8787
return (
88-
<ElementType {...rest} className={classes}>
88+
<ElementType {...rest} className={classes} id={id}>
8989
{errorLabelBefore}
9090
{createHTMLLabel(label, { autoGenerateKey: false })}
9191
{errorLabelAfter}

test/specs/collections/Form/FormField-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,21 @@ describe('FormField', () => {
198198
button.should.have.prop('content', 'Click Me')
199199
})
200200
})
201+
202+
describe('id', () => {
203+
it('is set when content is provided', () => {
204+
const wrapper = mount(<FormField content='content' id='testId' />)
205+
const fieldId = wrapper.getDOMNode().getAttribute('id')
206+
expect(fieldId).to.equal('testId')
207+
})
208+
it('is set when have child elements', () => {
209+
const wrapper = mount(
210+
<FormField id='testId'>
211+
<input />
212+
</FormField>,
213+
)
214+
const fieldId = wrapper.getDOMNode().getAttribute('id')
215+
expect(fieldId).to.equal('testId')
216+
})
217+
})
201218
})

0 commit comments

Comments
 (0)