Skip to content

Commit 8636c8e

Browse files
committed
facilitate server side rendering
1 parent f6e5325 commit 8636c8e

File tree

6 files changed

+289
-249
lines changed

6 files changed

+289
-249
lines changed

.size-snapshot.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"dist/index.js": {
3-
"bundled": 6414,
4-
"minified": 6414,
5-
"gzipped": 2026
3+
"bundled": 6537,
4+
"minified": 6537,
5+
"gzipped": 2070
66
},
77
"lib/cjs/index.js": {
8-
"bundled": 12375,
9-
"minified": 6670,
10-
"gzipped": 1957
8+
"bundled": 12566,
9+
"minified": 6825,
10+
"gzipped": 2015
1111
},
1212
"lib/esm/index.js": {
13-
"bundled": 12333,
14-
"minified": 6652,
15-
"gzipped": 1957,
13+
"bundled": 12524,
14+
"minified": 6807,
15+
"gzipped": 2017,
1616
"treeshaked": {
1717
"rollup": {
18-
"code": 6162,
18+
"code": 6285,
1919
"import_statements": 361
2020
},
2121
"webpack": {
22-
"code": 7467
22+
"code": 7592
2323
}
2424
}
2525
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# React Tooltip
22
[![npm version](https://img.shields.io/npm/v/react-popper-tooltip.svg?style=flat-square)](https://www.npmjs.com/package/react-popper-tooltip)
3-
[![npm downloads](https://img.shields.io/npm/dt/react-popper-tooltip.svg?style=flat-square)](https://www.npmjs.com/package/react-popper-tooltip)
4-
[![gzip size](https://img.badgesize.io/https://unpkg.com/react-popper-tooltip?compression=gzip&style=flat-square)](https://unpkg.com/react-popper-tooltip)
3+
[![npm downloads](https://img.shields.io/npm/dm/react-popper-tooltip.svg?style=flat-square)](https://www.npmjs.com/package/react-popper-tooltip)
54
[![Dependency Status](https://img.shields.io/david/mohsinulhaq/react-popper-tooltip.svg?style=flat-square)](https://david-dm.org/mohsinulhaq/react-popper-tooltip)
65
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
76
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)

src/TooltipTrigger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createPortal } from 'react-dom';
66
import T from 'prop-types';
77
import { Manager, Reference, Popper } from 'react-popper';
88
import Tooltip from './Tooltip';
9-
import { TooltipContext, callAll, noop } from './utils';
9+
import { TooltipContext, callAll, noop, canUseDOM } from './utils';
1010

1111
const DEFAULT_MODIFIERS = {
1212
preventOverflow: {
@@ -72,7 +72,7 @@ export default class TooltipTrigger extends PureComponent {
7272
/**
7373
* element to be used as portal container
7474
*/
75-
portalContainer: T.instanceOf(HTMLElement),
75+
portalContainer: canUseDOM() ? T.instanceOf(HTMLElement) : T.object,
7676
/**
7777
* modifiers passed directly to the underlying popper.js instance
7878
* For more information, refer to Popper.js’ modifier docs:
@@ -89,8 +89,8 @@ export default class TooltipTrigger extends PureComponent {
8989
trigger: 'hover',
9090
closeOnOutOfBoundaries: true,
9191
onVisibilityChange: noop,
92-
usePortal: true,
93-
portalContainer: document.body
92+
usePortal: canUseDOM(),
93+
portalContainer: canUseDOM() ? document.body : null
9494
};
9595

9696
state = {

src/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ export const callAll = (...fns) => (...args) =>
66
fns.forEach(fn => fn && fn(...args));
77

88
export const noop = () => {};
9+
10+
export const canUseDOM = () =>
11+
!!(
12+
typeof window !== 'undefined' &&
13+
window.document &&
14+
window.document.createElement
15+
);

typings/react-popper-tooltip.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ declare module 'react-popper-tooltip' {
115115
* Element to be used as portal container
116116
* Defaults to document.body.
117117
*/
118-
portalContainer?: HTMLElement;
118+
portalContainer?: any;
119119
/**
120120
* Modifiers passed directly to the underlying popper.js instance. For more
121121
* information, refer to Popper.js’ [modifier docs](https://popper.js.org/popper-documentation.html#modifiers).

0 commit comments

Comments
 (0)