Skip to content

Commit b35294d

Browse files
bolivierlayershifter
authored andcommitted
Add ref to components (#4373)
* Add ref to FormButton * Add ref to FormCheckbox * Add forwardRef to FormGroup * Remove accidental `only` calls
1 parent 0231064 commit b35294d

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

src/collections/Form/FormButton.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import FormField from './FormField'
1010
* @see Button
1111
* @see Form
1212
*/
13-
function FormButton(props) {
13+
const FormButton = React.forwardRef((props, ref) => {
1414
const { control } = props
1515
const rest = getUnhandledProps(FormButton, props)
1616
const ElementType = getElementType(FormButton, props)
1717

18-
return <ElementType {...rest} control={control} />
19-
}
18+
return <ElementType {...rest} control={control} ref={ref} />
19+
})
20+
21+
FormButton.displayName = 'FormButton'
2022

2123
FormButton.propTypes = {
2224
/** An element type to render as (string or function). */

src/collections/Form/FormCheckbox.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import FormField from './FormField'
1010
* @see Checkbox
1111
* @see Form
1212
*/
13-
function FormCheckbox(props) {
13+
const FormCheckbox = React.forwardRef((props, ref) => {
1414
const { control } = props
1515
const rest = getUnhandledProps(FormCheckbox, props)
1616
const ElementType = getElementType(FormCheckbox, props)
1717

18-
return <ElementType {...rest} control={control} />
19-
}
18+
return <ElementType {...rest} control={control} ref={ref} />
19+
})
20+
21+
FormCheckbox.displayName = 'FormCheckbox'
2022

2123
FormCheckbox.propTypes = {
2224
/** An element type to render as (string or function). */

src/collections/Form/FormGroup.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
* A set of fields can appear grouped together.
1616
* @see Form
1717
*/
18-
function FormGroup(props) {
18+
const FormGroup = React.forwardRef((props, ref) => {
1919
const { children, className, grouped, inline, unstackable, widths } = props
2020

2121
const classes = cx(
@@ -30,11 +30,13 @@ function FormGroup(props) {
3030
const ElementType = getElementType(FormGroup, props)
3131

3232
return (
33-
<ElementType {...rest} className={classes}>
33+
<ElementType {...rest} className={classes} ref={ref}>
3434
{children}
3535
</ElementType>
3636
)
37-
}
37+
})
38+
39+
FormGroup.displayName = 'FormGroup'
3840

3941
FormGroup.propTypes = {
4042
/** An element type to render as (string or function). */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ describe('FormButton', () => {
1515
.find('FormField')
1616
.should.have.prop('control', Button)
1717
})
18+
19+
common.forwardsRef(FormButton, { tagName: 'button' })
1820
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ describe('FormCheckbox', () => {
1414
.find('FormField')
1515
.should.have.prop('control', Checkbox)
1616
})
17+
18+
common.forwardsRef(FormCheckbox, { tagName: 'input' })
1719
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ describe('FormGroup', () => {
1616
common.propKeyOnlyToClassName(FormGroup, 'grouped')
1717
common.propKeyOnlyToClassName(FormGroup, 'inline')
1818
common.propKeyOnlyToClassName(FormGroup, 'unstackable')
19+
20+
common.forwardsRef(FormGroup)
1921
})

0 commit comments

Comments
 (0)