diff --git a/CHANGELOG.md b/CHANGELOG.md index 5216a8c..2ee1d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `Node#visible?` reported an open popover or modal dialog as hidden when an ancestor had `opacity: 0` [#328] - `Driver#window_handles` listed the web workers a page spawned as windows, so `window_opened_by` raised `opened 2 windows instead of 1` [#326] +- `Node#select_option` and `Node#unselect_option` didn't fire the `input` event on the select [#223] ### Removed diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 6329461..e8d2b28 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -429,13 +429,14 @@ class Cuprite { } else if (value == false && !node.parentNode.multiple) { return false; } else { - let parentNode = node.parentNode; - this.trigger(parentNode, "focus"); + let selectNode = node.closest("select"); + this.trigger(selectNode, "focus"); node.selected = value; + selectNode.dispatchEvent(new Event("input", { bubbles: true, composed: true })); this.changed(node); - this.trigger(parentNode, "blur"); + this.trigger(selectNode, "blur"); return true; } } diff --git a/spec/features/session_spec.rb b/spec/features/session_spec.rb index 54e113f..4058229 100644 --- a/spec/features/session_spec.rb +++ b/spec/features/session_spec.rb @@ -155,6 +155,11 @@ expect(@session.find(:css, "#changes").text).to eq("Firefox") end + it "fires the input event before the change event" do + expect(@session.find(:css, "#changes_on_input").text).to eq("Firefox") + expect(@session.find(:css, "#select_events").text).to eq("input change") + end + it "fires the blur event" do expect(@session.find(:css, "#changes_on_blur").text).to eq("Firefox") end @@ -177,6 +182,11 @@ expect(@session.find(:css, "#changes").text).to eq("Safari") end + it "fires the input event before the change event" do + expect(@session.find(:css, "#changes_on_input").text).to eq("Safari") + expect(@session.find(:css, "#select_events").text).to eq("input change") + end + it "fires the blur event" do expect(@session.find(:css, "#changes_on_blur").text).to eq("Safari") end diff --git a/spec/support/public/test.js b/spec/support/public/test.js index 4a275ee..340e84f 100644 --- a/spec/support/public/test.js +++ b/spec/support/public/test.js @@ -46,6 +46,11 @@ $(function() { .change(function(event) { $("#changes").text($(this).val()) $("#target_on_select").text(event.target.nodeName) + $("#select_events").append(" change") + }) + .bind("input", function() { + $("#changes_on_input").text($(this).val()) + $("#select_events").append(" input") }) .focus(function() { $("#changes_on_focus").text($(this).val()) diff --git a/spec/support/views/with_js.erb b/spec/support/views/with_js.erb index 0efae6f..c3cebb7 100644 --- a/spec/support/views/with_js.erb +++ b/spec/support/views/with_js.erb @@ -47,6 +47,7 @@
+