ContentEditable in Shadow DOM?

北城以北 提交于 2019-12-03 16:11:22

According to the spec 1 selection is somewhat open ended for implementors. It does mention:

Accordingly, selections may only exist within one node tree, because they are defined by a single range. The selection, returned by the window.getSelection() method never returns a selection within a shadow tree.

The getSelection() method of the shadow root object returns the current selection in this shadow tree.

Have you tried the shadow root's getSelection()?

you can use this:

const selection = shadowRoot.getSelection();
const range = selection.getRangeAt(0)
console.log(range.toString())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!