File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1717
1818(def ^:dynamic *force-set-dom-value* false )
1919
20+ (defn get-true-active-element []
21+ ; ; For controlled inputs `input-node-set-value` tries to do some heurestics to
22+ ; ; preserve the cursor position. But before doing so, it tries to find the active
23+ ; ; element in the document.
24+ ; ;
25+ ; ; Unfortunately, if an input element is inside a shadow dom, the
26+ ; ; activeElement points to the shadow root instead of the input element. This
27+ ; ; messes up the cursor perservation logic.
28+ ; ;
29+ ; ; But the saving grace here is that active input element can still be found
30+ ; ; by querying for the `.activeElement`` on the shadow-root.
31+ (let [active-element (.-activeElement js/document)]
32+ (if-let [shadow-root (.-shadowRoot active-element)]
33+ (.-activeElement shadow-root)
34+ active-element)))
35+
2036(defn input-node-set-value
2137 [node rendered-value dom-value ^clj component {:keys [on-write]}]
22- (if (or (not (and (identical? node (.-activeElement js/document ))
38+ (if (or (not (and (identical? node (get-true-active-element ))
2339 (has-selection-api? (.-type node))
2440 (string? rendered-value)
2541 (string? dom-value)))
You can’t perform that action at this time.
0 commit comments