Skip to content

Commit 93a9d0e

Browse files
committed
feat: attribute value-bubbles to define whether input event bubbles on element value is set on
1 parent bde8534 commit 93a9d0e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/setValue.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ HTMLHeadingElement.prototype.setValue = function (value, dispatch) {
1414

1515
// TODO: check if using a a switch case will provide better performance
1616
const setValue = (el, value, dispatch) => {
17+
let bubbles = el.hasAttribute("value-bubbles");
1718
let valueDispatch = el.hasAttribute("value-dispatch");
18-
if (
19-
(valueDispatch || valueDispatch === "") &&
20-
(value === "$false" || value === undefined || value === null)
21-
) {
22-
return dispatchEvents(el, dispatch);
19+
if (valueDispatch || valueDispatch === "") {
20+
if (value === "$false" || value === undefined || value === null)
21+
return dispatchEvents(el, bubbles, dispatch);
2322
}
2423

2524
if (value === null || value === undefined) return;
@@ -102,7 +101,7 @@ const setValue = (el, value, dispatch) => {
102101

103102
el.value = value;
104103
}
105-
dispatchEvents(el, dispatch);
104+
// dispatchEvents(el, bubbles, dispatch);
106105
} else if (el.tagName === "IMG" || el.tagName === "SOURCE") {
107106
el.src = value;
108107
} else if (el.tagName === "IFRAME") {
@@ -157,11 +156,9 @@ const setValue = (el, value, dispatch) => {
157156
if (el.hasAttribute("value")) {
158157
el.setAttribute("value", value);
159158
}
160-
161-
dispatchEvents(el, dispatch);
162159
}
163160

164-
if (el.getAttribute("contenteditable")) dispatchEvents(el, dispatch);
161+
// if (el.getAttribute("contenteditable")) dispatchEvents(el, bubbles, dispatch);
165162

166163
if (el.tagName == "HEAD" || el.tagName == "BODY") {
167164
el.removeAttribute("array");
@@ -173,6 +170,8 @@ const setValue = (el, value, dispatch) => {
173170
setScript(script);
174171
}
175172
}
173+
174+
dispatchEvents(el, bubbles, dispatch);
176175
};
177176

178177
function setState(el) {
@@ -220,9 +219,9 @@ function __decryptPassword(str) {
220219
return decode_str;
221220
}
222221

223-
function dispatchEvents(el, skip = true) {
222+
function dispatchEvents(el, bubbles = true, skip = true) {
224223
let inputEvent = new CustomEvent("input", {
225-
bubbles: true,
224+
bubbles,
226225
detail: {
227226
skip
228227
}
@@ -235,7 +234,7 @@ function dispatchEvents(el, skip = true) {
235234
el.dispatchEvent(inputEvent);
236235

237236
let changeEvent = new CustomEvent("change", {
238-
bubbles: true,
237+
bubbles,
239238
detail: {
240239
skip
241240
}

0 commit comments

Comments
 (0)