diff --git a/lib/capybara/cuprite/node.rb b/lib/capybara/cuprite/node.rb index 9c7b3d26..1a60911f 100644 --- a/lib/capybara/cuprite/node.rb +++ b/lib/capybara/cuprite/node.rb @@ -103,6 +103,8 @@ def set(value, options = {}) # rubocop:disable Metrics/CyclomaticComplexity, Met command(:select_file, files) when "color" node.evaluate("this.setAttribute('value', '#{value}')") + node.evaluate("this.dispatchEvent(new InputEvent('input'))") + node.evaluate("this.dispatchEvent(new Event('change', { bubbles: true }))") when "date" value = value.to_date.iso8601 if !value.is_a?(String) && value.respond_to?(:to_date) command(:set, value.to_s) diff --git a/spec/features/session_spec.rb b/spec/features/session_spec.rb index 05891601..2169eed4 100644 --- a/spec/features/session_spec.rb +++ b/spec/features/session_spec.rb @@ -350,6 +350,18 @@ expect(element.value).to eq("2023-W39") end end + + it "fires the change event for a color input" do + element = @session.find(:css, "#change_me_color") + element.set("#ddeeff") + expect(@session.find(:css, "#changes").text).to eq("#ddeeff") + end + + it "fires the input event for a color input" do + element = @session.find(:css, "#change_me_color") + element.set("#ddeeff") + expect(@session.find(:css, "#changes_on_input").text).to eq("#ddeeff") + end end describe "Node#visible" do diff --git a/spec/support/public/test.js b/spec/support/public/test.js index 7b11808e..6dc31950 100644 --- a/spec/support/public/test.js +++ b/spec/support/public/test.js @@ -34,6 +34,14 @@ $(function() { $("#changes_on_blur").text("Blur") }) + $("#change_me_color") + .change(function(event) { + $("#changes").text($(this).val()) + }) + .bind("input", function(event) { + $("#changes_on_input").text($(this).val()) + }) + $("#browser") .change(function(event) { $("#changes").text($(this).val())