Skip to content

Commit

Permalink
feat(Popover): add tetherRef to Popover (#183)
Browse files Browse the repository at this point in the history
This will pass any additional props provided to popover down to the
inner div as well as the tetherRef to the TetherContent.
  • Loading branch information
TheSharpieOne authored and eddywashere committed Oct 18, 2016
1 parent 6be1a67 commit 00d08ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/lib/Components/PopoversPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default class PopoversPage extends React.Component {
// target div ID, popover is attached to this element
tether: PropTypes.object,
// optionally overide tether config http://tether.io/#options
tetherRef: PropType.function,
// function which is passed a reference to the instance of tether for manually \`position()\`ing
placement: PropTypes.oneOf([
'top',
'bottom',
Expand Down
17 changes: 13 additions & 4 deletions src/Popover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { PropTypes } from 'react';
import classNames from 'classnames';
import omit from 'lodash.omit';
import TetherContent from './TetherContent';
import { getTetherAttachments, tetherAttachements } from './utils';

Expand All @@ -7,7 +9,8 @@ const propTypes = {
target: PropTypes.string.isRequired,
isOpen: PropTypes.bool,
tether: PropTypes.object,
children: PropTypes.node,
tetherRef: PropTypes.func,
className: PropTypes.string,
toggle: PropTypes.func
};

Expand Down Expand Up @@ -50,16 +53,22 @@ class Popover extends React.Component {

let tetherConfig = this.getTetherConfig();

const classes = classNames(
'popover-inner',
this.props.className
);

const attributes = omit(this.props, Object.keys(propTypes));

return (
<TetherContent
arrow="popover"
tether={tetherConfig}
tetherRef={this.props.tetherRef}
isOpen={this.props.isOpen}
toggle={this.props.toggle}
>
<div className="popover-inner">
{this.props.children}
</div>
<div {...attributes} className={classes} />
</TetherContent>
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,17 @@ describe('Popover', () => {

wrapper.unmount();
});

it('should allow custom classes to be added to the popover-inner', () => {
const wrapper = mount(
<Popover isOpen placement={placement} target="popover-target" className="popover-special">
<PopoverTitle>Title</PopoverTitle>
<PopoverContent>Content</PopoverContent>
</Popover>
);

expect(document.getElementsByClassName('popover-inner')[0].className.indexOf('popover-special') > -1).toBe(true);

wrapper.unmount();
});
});

0 comments on commit 00d08ad

Please sign in to comment.