Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Various dysfunctional behaviors when using with shadow DOM (potential fix) #327

@datori

Description

@datori

Hello, I've been working on getting Squire working within a Polymer application, but I initially ran into a couple problems. Primary issues included the application failing to properly track cursor location, similar issues with text editing, and several issues vaguely related to focus. After tinkering with squire-raw.js for a while, it seems like the issue was being caused by two functions in particular, Squire.prototype.fireEvent and getWindowSelection.

With Squire.prototype.fireEvent, the line isFocused = this._root === this._doc.activeElement; is referencing the activeElement on this._doc, which is a direct reference to the document node. The issue arises because shadow DOMs have their own activeElement property, and therefore the shadow root that a given node is attached to is the only one capable of directly observing that node. When a node nested within a shadow DOM is active, the document can only see that the shadow host of that node is active, and thus the focus check fails since it compares the nested node to the 'active' shadow host. My workaround has been to replace the aforementioned line with isFocused = this._root === this._root.getRootNode().activeElement, which instead references the activeElement of the node to which the element is directly attached.

Similarly, the issue with getWindowSelection arises because it references the getSelection method of self._win, when it should reference the shadow root's. My solution was to replace the implementation with return self._root.getRootNode().getSelection() || null;

Thanks, and let me know if I missed anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions