Skip to content

Commit a2a33e3

Browse files
committed
fix(Tooltip/Popover): fix className/add innerClassName
1 parent 759934b commit a2a33e3

6 files changed

Lines changed: 52 additions & 5 deletions

File tree

docs/lib/Components/PopoversPage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export default class PopoversPage extends React.Component {
3737
]).isRequired,
3838
// Where to inject the popper DOM node, default to body
3939
container: PropTypes.oneOfType([PropTypes.string, PropTypes.func, DOMElement]),
40+
className: PropTypes.string,
41+
// Apply class to the inner-popover
42+
innerClassName: PropTypes.string,
4043
disabled: PropTypes.bool,
4144
placementPrefix: PropTypes.string,
4245
delay: PropTypes.oneOfType([

docs/lib/Components/TooltipsPage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export default class TooltipsPage extends React.Component {
4747
PropTypes.shape({ show: PropTypes.number, hide: PropTypes.number }),
4848
PropTypes.number
4949
]),
50+
className: PropTypes.string,
51+
// Apply class to the inner-tooltip
52+
innerClassName: PropTypes.string,
5053
// optionally hide tooltip when hovering over tooltip content - default true
5154
autohide: PropTypes.bool,
5255
// convenience attachments for popover

src/Popover.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const propTypes = {
2020
isOpen: PropTypes.bool,
2121
disabled: PropTypes.bool,
2222
className: PropTypes.string,
23+
innerClassName: PropTypes.string,
2324
placementPrefix: PropTypes.string,
2425
cssModule: PropTypes.object,
2526
toggle: PropTypes.func,
@@ -153,12 +154,13 @@ class Popover extends React.Component {
153154
const attributes = omit(this.props, Object.keys(propTypes));
154155
const classes = mapToCssModules(classNames(
155156
'popover-inner',
156-
this.props.className
157+
this.props.innerClassName
157158
), this.props.cssModule);
158159

159160
const popperClasses = mapToCssModules(classNames(
160161
'popover',
161-
'show'
162+
'show',
163+
this.props.className
162164
), this.props.cssModule);
163165

164166
return (

src/Tooltip.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const propTypes = {
2020
isOpen: PropTypes.bool,
2121
disabled: PropTypes.bool,
2222
className: PropTypes.string,
23+
innerClassName: PropTypes.string,
2324
cssModule: PropTypes.object,
2425
toggle: PropTypes.func,
2526
autohide: PropTypes.bool,
@@ -178,12 +179,13 @@ class Tooltip extends React.Component {
178179
const attributes = omit(this.props, Object.keys(propTypes));
179180
const classes = mapToCssModules(classNames(
180181
'tooltip-inner',
181-
this.props.className
182+
this.props.innerClassName
182183
), this.props.cssModule);
183184

184185
const popperClasses = mapToCssModules(classNames(
185186
'tooltip',
186-
'show'
187+
'show',
188+
this.props.className
187189
), this.props.cssModule);
188190

189191
return (

src/__tests__/Popover.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('Popover', () => {
142142

143143
it('should allow custom classes to be added to the popover-inner', () => {
144144
const wrapper = mount(
145-
<Popover isOpen placement={placement} target="innerTarget" className="popover-special">
145+
<Popover isOpen placement={placement} target="innerTarget" innerClassName="popover-special">
146146
<PopoverHeader>Title</PopoverHeader>
147147
<PopoverBody>Content</PopoverBody>
148148
</Popover>
@@ -153,6 +153,19 @@ describe('Popover', () => {
153153
wrapper.unmount();
154154
});
155155

156+
it('should allow custom classes to be added to the popover', () => {
157+
const wrapper = mount(
158+
<Popover isOpen placement={placement} target="innerTarget" className="popover-special">
159+
<PopoverHeader>Title</PopoverHeader>
160+
<PopoverBody>Content</PopoverBody>
161+
</Popover>
162+
);
163+
164+
expect(document.getElementsByClassName('popover')[0].className.indexOf('popover-special') > -1).toBe(true);
165+
166+
wrapper.unmount();
167+
});
168+
156169
it('should not handle outside of target clicks when isOpen is false', () => {
157170
const wrapper = mount(
158171
<Popover target="innerTarget" isOpen={isOpen} toggle={toggle}>

src/__tests__/Tooltip.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ describe('Tooltip', () => {
171171
wrapper.detach();
172172
});
173173

174+
it('should allow custom classes to be added to the tooltip-inner', () => {
175+
const wrapper = mount(
176+
<Tooltip isOpen target="target" innerClassName="tooltip-special">
177+
Tooltip Content
178+
</Tooltip>
179+
);
180+
181+
expect(document.getElementsByClassName('tooltip-inner')[0].className.indexOf('tooltip-special') > -1).toBe(true);
182+
183+
wrapper.unmount();
184+
});
185+
186+
it('should allow custom classes to be added to the tooltip', () => {
187+
const wrapper = mount(
188+
<Tooltip isOpen target="target" className="tooltip-special">
189+
Tooltip Content
190+
</Tooltip>
191+
);
192+
193+
expect(document.getElementsByClassName('tooltip')[0].className.indexOf('tooltip-special') > -1).toBe(true);
194+
195+
wrapper.unmount();
196+
});
197+
174198
it('should not call props.toggle when disabled ', () => {
175199
const props = createSpyObj('props', ['toggle']);
176200
const event = createSpyObj('event', ['preventDefault']);

0 commit comments

Comments
 (0)