Skip to content

Commit

Permalink
Send correct inputType when typing (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindagruenwald authored Sep 22, 2023
1 parent cc26d52 commit 7326bff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/capybara/cuprite/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ class Cuprite {
}

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

Expand Down
5 changes: 5 additions & 0 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,11 @@ def create_screenshot(file, *args)
expect(input.value).to eq("abc")
end

it "uses the 'insertText' inputType for input event" do
input.set("a")
expect(output["data-input-type"]).to eq("insertText")
end

it "doesn't call the change event if there is no change" do
input.set("a")
input.set("a")
Expand Down
5 changes: 4 additions & 1 deletion spec/support/views/input_events.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
const log = (s) => output.textContent = `${output.textContent} ${s}`
input.addEventListener('keydown', () => log('keydown'))
input.addEventListener('keypress', () => log('keypress'))
input.addEventListener('input', () => log('input'))
input.addEventListener('input', (event) => {
log('input');
output.dataset.inputType = event.inputType;
})
input.addEventListener('keyup', () => log('keyup'))
input.addEventListener('change', () => log('change'))
</script>
Expand Down

0 comments on commit 7326bff

Please sign in to comment.