emoji-picker-element/src/picker/utils/calculateTextWidth.js

8 lines
278 B
JavaScript
Raw Normal View History

2020-05-18 00:31:20 +02:00
// get the width of the text inside of a DOM node, via https://stackoverflow.com/a/59525891/680742
let range
2020-06-01 03:05:51 +02:00
export function calculateTextWidth (node) {
2020-05-18 00:31:20 +02:00
range = range || document.createRange()
range.selectNode(node.firstChild)
return range.getBoundingClientRect().width
}