Skip to content

Commit

Permalink
fix(TabContent): support for ref attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Oct 4, 2019
1 parent e70024c commit 334ff8d
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/TabContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,37 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import { createBootstrapComponent } from './ThemeProvider';
import { useBootstrapPrefix } from './ThemeProvider';

class TabContent extends React.Component {
static propTypes = {
/**
* @default 'tab-content'
*/
bsPrefix: PropTypes.string,
const TabContent = React.forwardRef(
(
{
bsPrefix,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
className,
...props
},
ref,
) => {
const decoratedBsPrefix = useBootstrapPrefix(bsPrefix, 'tab-content');
return (
<Component
ref={ref}
{...props}
className={classNames(className, decoratedBsPrefix)}
/>
);
},
);

as: PropTypes.elementType,
};
TabContent.propTypes = {
/**
* @default 'tab-content'
*/
bsPrefix: PropTypes.string,

render() {
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
const { bsPrefix, as: Component = 'div', className, ...props } = this.props;
as: PropTypes.elementType,
};

return <Component {...props} className={classNames(className, bsPrefix)} />;
}
}

export default createBootstrapComponent(TabContent, 'tab-content');
export default TabContent;

0 comments on commit 334ff8d

Please sign in to comment.