Skip to content

Commit 171c42c

Browse files
davidrungerroute
andauthored
Generate a FocusEvent (not Event) for focus-related events (#272)
* chore: add missing changelog entries * Generate a FocusEvent (not Event) for focus-related events * chore: add changelog --------- Co-authored-by: Dmitry Vorotilin <d.vorotilin@gmail.com>
1 parent 050cb4f commit 171c42c

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Treat non-summary descendants of a closed `<details>` element as non-visible [#317]
2121
- `switch_to_window` sends `Target.activateTarget` so Chrome reactivates the window's renderer immediately instead of leaving it backgrounded, which could stall the next input command for several seconds [#321]
2222
- `Node#set` fires `input` and `change` events for a `color` input, since its value can only be set via JavaScript and never gets them naturally [#229]
23+
- Generate a `FocusEvent` (not a generic `Event`) for focus-related events (`blur`, `focus`, `focusin`, `focusout`), matching real browser behavior [#272]
2324

2425
### Removed
2526

lib/capybara/cuprite/javascripts/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class Cuprite {
464464
options["button"] || 0, null
465465
)
466466
} else if (EVENTS.FOCUS.indexOf(name) != -1) {
467-
event = this.obtainEvent(name);
467+
event = new FocusEvent(name, { bubbles: true, cancelable: true });
468468
} else if (EVENTS.FORM.indexOf(name) != -1) {
469469
event = this.obtainEvent(name);
470470
} else {

spec/features/session_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@
227227
end
228228

229229
it "fires the focus event" do
230-
expect(@session.find(:css, "#changes_on_focus").text).to eq("Focus")
230+
expect(@session.find(:css, "#changes_on_focus").text).to eq("Focus (FocusEvent)")
231231
end
232232

233233
it "fires the blur event" do
234-
expect(@session.find(:css, "#changes_on_blur").text).to eq("Blur")
234+
expect(@session.find(:css, "#changes_on_blur").text).to eq("Blur (FocusEvent)")
235235
end
236236

237237
it "fires the keydown event before the value is updated" do

spec/support/public/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ $(function() {
2828
$("#changes_on_keypress").text(increment)
2929
})
3030
.focus(function(event) {
31-
$("#changes_on_focus").text("Focus")
31+
$("#changes_on_focus").text(`Focus (${event.originalEvent.constructor.name})`)
3232
})
33-
.blur(function() {
34-
$("#changes_on_blur").text("Blur")
33+
.blur(function(event) {
34+
$("#changes_on_blur").text(`Blur (${event.originalEvent.constructor.name})`)
3535
})
3636

3737
$("#change_me_color")

0 commit comments

Comments
 (0)