Skip to content

Commit

Permalink
feat: Migrate Tooltip to be a ref forwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
bpas247 committed Jul 28, 2019
1 parent 8cb7306 commit df29001
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import isRequiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
import { createBootstrapComponent } from './ThemeProvider';
import { useBootstrapPrefix } from './ThemeProvider';

const propTypes = {
/**
Expand Down Expand Up @@ -54,9 +54,6 @@ const propTypes = {
style: PropTypes.object,
}),

/** @private */
innerRef: PropTypes.any,

/** @private */
scheduleUpdate: PropTypes.func,

Expand All @@ -68,34 +65,40 @@ const defaultProps = {
placement: 'right',
};

function Tooltip({
bsPrefix,
innerRef,
placement,
className,
style,
children,
arrowProps,
scheduleUpdate: _,
outOfBoundaries: _1,
...props
}) {
return (
<div
ref={innerRef}
style={style}
role="tooltip"
x-placement={placement}
className={classNames(className, bsPrefix, `bs-tooltip-${placement}`)}
{...props}
>
<div className="arrow" {...arrowProps} />
<div className={`${bsPrefix}-inner`}>{children}</div>
</div>
);
}
const Tooltip = React.forwardRef(
(
{
bsPrefix,
placement,
className,
style,
children,
arrowProps,
scheduleUpdate: _,
outOfBoundaries: _1,
...props
},
ref,
) => {
bsPrefix = useBootstrapPrefix(bsPrefix, 'tooltip');

return (
<div
ref={ref}
style={style}
role="tooltip"
x-placement={placement}
className={classNames(className, bsPrefix, `bs-tooltip-${placement}`)}
{...props}
>
<div className="arrow" {...arrowProps} />
<div className={`${bsPrefix}-inner`}>{children}</div>
</div>
);
},
);

Tooltip.propTypes = propTypes;
Tooltip.defaultProps = defaultProps;

export default createBootstrapComponent(Tooltip, 'tooltip');
export default Tooltip;

0 comments on commit df29001

Please sign in to comment.