Skip to content

Commit 7ccd834

Browse files
authored
Merge pull request #262 from wwayne/nodelist-convert
Fix nodelist converte in safari
2 parents 661a384 + fbab9c5 commit 7ccd834

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import getEffect from './decorators/getEffect'
1515
import getPosition from './utils/getPosition'
1616
import getTipContent from './utils/getTipContent'
1717
import { parseAria } from './utils/aria'
18-
19-
import createArrayFromMixed from 'fbjs/lib/createArrayFromMixed'
18+
import nodeListToArray from './utils/nodeListToArray'
2019

2120
/* CSS */
2221
import cssStyle from './style'
@@ -148,15 +147,13 @@ class ReactTooltip extends Component {
148147
*/
149148
getTargetArray (id) {
150149
let targetArray
151-
152150
if (!id) {
153151
targetArray = document.querySelectorAll('[data-tip]:not([data-for])')
154152
} else {
155153
targetArray = document.querySelectorAll(`[data-tip][data-for="${id}"]`)
156154
}
157-
158155
// targetArray is a NodeList, convert it to a real array
159-
return createArrayFromMixed(targetArray)
156+
return nodeListToArray(targetArray)
160157
}
161158

162159
/**

src/utils/nodeListToArray.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Convert nodelist to array
3+
* @see https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/core/createArrayFromMixed.js#L24
4+
* NodeLists are functions in Safari
5+
*/
6+
7+
export default function (nodeList) {
8+
const length = nodeList.length
9+
if (nodeList.hasOwnProperty) {
10+
return Array.prototype.slice.call(nodeList)
11+
}
12+
return new Array(length).fill().map(index => nodeList[index])
13+
}

0 commit comments

Comments
 (0)