Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bubbling change event on inputs and textareas #199

Merged
merged 8 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- version -->
# 14.16.0 API Reference
# 15.0.0 API Reference
<!-- versionstop -->

<!-- toc -->
Expand Down
6 changes: 3 additions & 3 deletions lib/HTMLInputElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = class HTMLInputElement extends HTMLElement {
return this.$elm.prop("checked");
}
set checked(value) {
const checked = this.$elm.prop("checked");
switch (this.type) {
case "checkbox":
break;
Expand All @@ -39,8 +38,6 @@ module.exports = class HTMLInputElement extends HTMLElement {
}

this.$elm.prop("checked", !!value);
if (checked === !!value) this.dispatchEvent(new InputEvent("input"));

return value;
}
get disabled() {
Expand Down Expand Up @@ -97,13 +94,16 @@ module.exports = class HTMLInputElement extends HTMLElement {
case "number":
case "url":
this.dispatchEvent(new InputEvent("input"));
this.dispatchEvent(new InputEvent("change"), { bubbles: true });
break;
case "file":
if (!val) this[kFiles].length = 0;
this.dispatchEvent(new Event("input"));
this.dispatchEvent(new InputEvent("change"), { bubbles: true });
break;
default:
this.dispatchEvent(new Event("input"));
this.dispatchEvent(new InputEvent("change"), { bubbles: true });
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/HTMLSelectElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module.exports = class HTMLSelectElement extends HTMLElement {
options.selectedIndex = idx;
if (oldIdx !== options.selectedIndex) {
this.dispatchEvent(new Event("input"));
this.dispatchEvent(new Event("change", { bubbles: true }));
}
return val;
}
Expand Down
1 change: 1 addition & 0 deletions lib/HTMLTextAreaElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = class HTMLTextAreaElement extends HTMLElement {
if (oldVal !== val) {
this.setAttribute("value", val);
this.dispatchEvent(new InputEvent("input"));
this.dispatchEvent(new InputEvent("change", { bubbles: true }));
}

return val;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressen/tallahassee",
"version": "14.16.0",
"version": "15.0.0",
"description": "Lightweight client testing framework",
"main": "index.js",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion test/elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ describe("elements", () => {
expect(elm.checked).to.be.true;
});

it("does NOT emit change when checked", () => {
it("does not emit change when checked", () => {
const elm = document.getElementsByTagName("input")[1];
let eventFired = false;
elm.addEventListener("change", () => {
Expand Down
7 changes: 7 additions & 0 deletions test/form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ describe("forms", () => {

el.value = "1";
});

it(`should fire 'change' event on ${tagName} when value is changed`, (done) => {
const el = document.querySelector(tagName);
el.addEventListener("change", () => done());

el.value = "1";
});
});
});
});
Loading