Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- `Node#select_option` and `Node#unselect_option` didn't fire the `input` event on the select [#223]
- `Node#trigger` silently dispatched nothing for events other than mouse, focus and `submit`, such as `input`,
`change` or custom events [#197]
- `Node#set` with an empty string cleared a text field without firing the `input` event [#164]

### Removed

Expand Down
8 changes: 6 additions & 2 deletions lib/capybara/cuprite/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ class Cuprite {

this.keyupdowned(node, "keyup", char, keyCode);
}

if (valueBefore !== "" && node.value === "") {
this.input(node, "deleteContentBackward");
}
}

if (valueBefore !== node.value) {
Expand All @@ -238,8 +242,8 @@ class Cuprite {
return nativeTextareaValueSetter.call(node, value);
}

input(node) {
let event = new InputEvent("input", { inputType: "insertText", bubbles: true, cancelable: false });
input(node, inputType = "insertText") {
let event = new InputEvent("input", { inputType: inputType, bubbles: true, cancelable: false });
node.dispatchEvent(event);
}

Expand Down
13 changes: 13 additions & 0 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,19 @@ def create_screenshot(file, *args)
input.set("a")
expect(output.text).to eq("keydown keypress input keyup change keydown keypress input keyup")
end

it "calls the input event when clearing the value" do
input.set("a")
input.set("")
expect(output.text).to eq("keydown keypress input keyup change input change")
expect(output["data-input-type"]).to eq("deleteContentBackward")
expect(input.value).to be_empty
end

it "doesn't call the input event when clearing an empty value" do
input.set("")
expect(output.text).to be_empty
end
end
end

Expand Down
Loading