Skip to content

Commit

Permalink
fix(FormLabel): forward ref when rendering as Col (#5835)
Browse files Browse the repository at this point in the history
  • Loading branch information
agwells authored and kyletsang committed Jun 3, 2021
1 parent 4ee2011 commit 98b6b87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/FormLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ const FormLabel: FormLabel = React.forwardRef(

if (column)
return (
<Col as="label" className={classes} htmlFor={htmlFor} {...props} />
<Col
ref={ref as React.ForwardedRef<HTMLLabelElement>}
as="label"
className={classes}
htmlFor={htmlFor}
{...props}
/>
);

return (
Expand Down
21 changes: 21 additions & 0 deletions test/FormLabelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ describe('<FormLabel>', () => {
expect(instance.input.tagName).to.equal('LABEL');
});

it('should support ref forwarding when rendered as a Col', () => {
class Container extends React.Component {
render() {
return (
<FormGroup controlId="foo">
<FormLabel
type="text"
column
ref={(ref) => {
this.input = ref;
}}
/>
</FormGroup>
);
}
}

const instance = mount(<Container />).instance();
expect(instance.input.tagName).to.equal('LABEL');
});

it('accepts as prop', () => {
mount(<FormLabel as="legend">body</FormLabel>).assertSingle('legend');
});
Expand Down

0 comments on commit 98b6b87

Please sign in to comment.