Skip to content

Commit 7326bff

Browse files
Send correct inputType when typing (#244)
1 parent cc26d52 commit 7326bff

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/capybara/cuprite/javascripts/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ class Cuprite {
180180
}
181181

182182
input(node) {
183-
let event = document.createEvent("HTMLEvents");
184-
event.initEvent("input", true, false);
183+
let event = new InputEvent("input", { inputType: "insertText", bubbles: true, cancelable: false });
185184
node.dispatchEvent(event);
186185
}
187186

spec/features/driver_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,11 @@ def create_screenshot(file, *args)
14701470
expect(input.value).to eq("abc")
14711471
end
14721472

1473+
it "uses the 'insertText' inputType for input event" do
1474+
input.set("a")
1475+
expect(output["data-input-type"]).to eq("insertText")
1476+
end
1477+
14731478
it "doesn't call the change event if there is no change" do
14741479
input.set("a")
14751480
input.set("a")

spec/support/views/input_events.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
const log = (s) => output.textContent = `${output.textContent} ${s}`
1010
input.addEventListener('keydown', () => log('keydown'))
1111
input.addEventListener('keypress', () => log('keypress'))
12-
input.addEventListener('input', () => log('input'))
12+
input.addEventListener('input', (event) => {
13+
log('input');
14+
output.dataset.inputType = event.inputType;
15+
})
1316
input.addEventListener('keyup', () => log('keyup'))
1417
input.addEventListener('change', () => log('change'))
1518
</script>

0 commit comments

Comments
 (0)