Skip to content

Commit

Permalink
feat(Popover/Tooltip): add boundariesElement prop (reactstrap#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
monteith authored and TheSharpieOne committed Aug 1, 2018
1 parent e941dfd commit 02b4555
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/lib/Components/PopoversPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class PopoversPage extends React.Component {
isOpen: PropTypes.bool,
// callback for toggling isOpen in the controlling component
toggle: PropTypes.func,
// boundaries for popper, can be scrollParent, window, viewport, or any DOM element
boundariesElement: PropTypes.string,
target: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
Expand Down
2 changes: 2 additions & 0 deletions docs/lib/Components/TooltipsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class TooltipsPage extends React.Component {
<pre>
<PrismCode className="language-jsx">
{`Tooltip.propTypes = {
// boundaries for popper, can be scrollParent, window, viewport, or any DOM element
boundariesElement: PropTypes.string,
// boolean to control the state of the tooltip
isOpen: PropTypes.bool,
hideArrow: PropTypes.bool,
Expand Down
2 changes: 2 additions & 0 deletions src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const propTypes = {
PropTypes.func,
DOMElement,
]),
boundariesElement: PropTypes.string,
isOpen: PropTypes.bool,
disabled: PropTypes.bool,
hideArrow: PropTypes.bool,
Expand Down Expand Up @@ -182,6 +183,7 @@ class Popover extends React.Component {
container={this.props.container}
modifiers={this.props.modifiers}
offset={this.props.offset}
boundariesElement={this.props.boundariesElement}
>
<div {...attributes} className={classes} ref={this.getRef} />
</PopperContent>
Expand Down
4 changes: 4 additions & 0 deletions src/PopperContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ const propTypes = {
container: PropTypes.oneOfType([PropTypes.string, PropTypes.func, DOMElement]),
target: PropTypes.oneOfType([PropTypes.string, PropTypes.func, DOMElement]).isRequired,
modifiers: PropTypes.object,
boundariesElement: PropTypes.string,
};

const defaultProps = {
boundariesElement: 'scrollParent',
placement: 'auto',
hideArrow: false,
isOpen: false,
Expand Down Expand Up @@ -144,6 +146,7 @@ class PopperContent extends React.Component {
tag,
container,
modifiers,
boundariesElement,
...attrs
} = this.props;
const arrowClassName = mapToCssModules(classNames(
Expand All @@ -159,6 +162,7 @@ class PopperContent extends React.Component {
const extendedModifiers = {
offset: { offset },
flip: { enabled: flip, behavior: fallbackPlacement },
preventOverflow: { boundariesElement },
update: {
enabled: true,
order: 950,
Expand Down
2 changes: 2 additions & 0 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const propTypes = {
isOpen: PropTypes.bool,
disabled: PropTypes.bool,
hideArrow: PropTypes.bool,
boundariesElement: PropTypes.string,
className: PropTypes.string,
innerClassName: PropTypes.string,
arrowClassName: PropTypes.string,
Expand Down Expand Up @@ -247,6 +248,7 @@ class Tooltip extends React.Component {
target={this.props.target}
isOpen={this.props.isOpen}
hideArrow={this.props.hideArrow}
boundariesElement={this.props.boundariesElement}
placement={this.props.placement}
placementPrefix={this.props.placementPrefix}
arrowClassName={this.props.arrowClassName}
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/Uncontrolled.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ describe('UncontrolledTooltip', () => {
tooltip.update();
expect(tooltip.prop('isOpen')).toBe(true);
});

it('should have boundary set to string', () => {
const tooltip = shallow(<UncontrolledTooltip boundariesElement="window" target="blah">Yo!</UncontrolledTooltip>);
expect(tooltip.prop('boundariesElement')).toBe('window');
});
});

0 comments on commit 02b4555

Please sign in to comment.