1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-20 13:22:04 +02:00

Check if getBoundingClientRect exist before trying to call bind (#5226)

* Stop trying to call bind on undifined when getBoundingClientRect is not defined. This is happening when testing slate with react testing library

* Add changeset
This commit is contained in:
Laufey Rut Guðmundsdóttir 2022-12-19 17:51:13 +00:00 committed by GitHub
parent 224b7ebba3
commit 0141f68365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': minor
---
Check if getBoundingClientRect exist before trying to call bind on it. Makes unit testing experience agains Editable nicer

View File

@ -1691,8 +1691,9 @@ const defaultScrollSelectionIntoView = (
// This was affecting the selection of multiple blocks and dragging behavior,
// so enabled only if the selection has been collapsed.
if (
!editor.selection ||
(editor.selection && Range.isCollapsed(editor.selection))
domRange.getBoundingClientRect &&
(!editor.selection ||
(editor.selection && Range.isCollapsed(editor.selection)))
) {
const leafEl = domRange.startContainer.parentElement!
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)