Skip to content

Commit 00d08ad

Browse files
TheSharpieOneeddywashere
authored andcommitted
feat(Popover): add tetherRef to Popover (#183)
This will pass any additional props provided to popover down to the inner div as well as the tetherRef to the TetherContent.
1 parent 6be1a67 commit 00d08ad

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

docs/lib/Components/PopoversPage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default class PopoversPage extends React.Component {
3434
// target div ID, popover is attached to this element
3535
tether: PropTypes.object,
3636
// optionally overide tether config http://tether.io/#options
37+
tetherRef: PropType.function,
38+
// function which is passed a reference to the instance of tether for manually \`position()\`ing
3739
placement: PropTypes.oneOf([
3840
'top',
3941
'bottom',

src/Popover.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, { PropTypes } from 'react';
2+
import classNames from 'classnames';
3+
import omit from 'lodash.omit';
24
import TetherContent from './TetherContent';
35
import { getTetherAttachments, tetherAttachements } from './utils';
46

@@ -7,7 +9,8 @@ const propTypes = {
79
target: PropTypes.string.isRequired,
810
isOpen: PropTypes.bool,
911
tether: PropTypes.object,
10-
children: PropTypes.node,
12+
tetherRef: PropTypes.func,
13+
className: PropTypes.string,
1114
toggle: PropTypes.func
1215
};
1316

@@ -50,16 +53,22 @@ class Popover extends React.Component {
5053

5154
let tetherConfig = this.getTetherConfig();
5255

56+
const classes = classNames(
57+
'popover-inner',
58+
this.props.className
59+
);
60+
61+
const attributes = omit(this.props, Object.keys(propTypes));
62+
5363
return (
5464
<TetherContent
5565
arrow="popover"
5666
tether={tetherConfig}
67+
tetherRef={this.props.tetherRef}
5768
isOpen={this.props.isOpen}
5869
toggle={this.props.toggle}
5970
>
60-
<div className="popover-inner">
61-
{this.props.children}
62-
</div>
71+
<div {...attributes} className={classes} />
6372
</TetherContent>
6473
);
6574
}

src/__tests__/Popover.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,17 @@ describe('Popover', () => {
134134

135135
wrapper.unmount();
136136
});
137+
138+
it('should allow custom classes to be added to the popover-inner', () => {
139+
const wrapper = mount(
140+
<Popover isOpen placement={placement} target="popover-target" className="popover-special">
141+
<PopoverTitle>Title</PopoverTitle>
142+
<PopoverContent>Content</PopoverContent>
143+
</Popover>
144+
);
145+
146+
expect(document.getElementsByClassName('popover-inner')[0].className.indexOf('popover-special') > -1).toBe(true);
147+
148+
wrapper.unmount();
149+
});
137150
});

0 commit comments

Comments
 (0)