use-editable
use-editable copied to clipboard
Fix: support iframes and portals
The problem I faced is that I render editable elements in an iframe (forced by CSS I'm dependent on, long story). I use React.Portal and because the code is defined in the main window and the elements are in different the library gets confused and ends up with Uncaught DOMException: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index. on any commit.
The fix is to allow to pass reference object to the window from the iframe.
It will use window of the element and fallback to global window otherwise. This had to be applied to all window and document references. It was tested in the iframe, selection control and updates works. Range doesn't throw anymore.