Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform ref forwarding in Form.Label when rendering as a Col #5835

Merged
merged 1 commit into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/FormLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ const FormLabel: BsPrefixRefForwardingComponent<'label', FormLabelProps> =

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