Skip to content

Commit 3a42de2

Browse files
committed
feat(core events): Add focusin and focusout event factories.
1 parent b1b4601 commit 3a42de2

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/core/events.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const await_pattern_init = (pattern) => {
172172
* A event factory for a bubbling and cancelable generic event.
173173
*
174174
* @param {string} name - The event name.
175-
* @returns {Event} - Returns a blur event.
175+
* @returns {Event} - Returns a DOM event.
176176
*/
177177
const generic_event = (name) => {
178178
return new Event(name, {
@@ -231,6 +231,20 @@ const focus_event = () => {
231231
});
232232
};
233233

234+
const focusin_event = () => {
235+
return new Event("focusin", {
236+
bubbles: true,
237+
cancelable: false,
238+
});
239+
};
240+
241+
const focusout_event = () => {
242+
return new Event("focusout", {
243+
bubbles: true,
244+
cancelable: false,
245+
});
246+
};
247+
234248
const input_event = () => {
235249
return new Event("input", {
236250
bubbles: true,
@@ -293,6 +307,8 @@ export default {
293307
click_event: click_event,
294308
change_event: change_event,
295309
focus_event: focus_event,
310+
focusin_event: focusin_event,
311+
focusout_event: focusout_event,
296312
input_event: input_event,
297313
mousedown_event: mousedown_event,
298314
mouseup_event: mouseup_event,

src/core/events.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,24 @@ describe("core.events tests", () => {
529529
expect(catched).toBe("inner");
530530
});
531531

532+
it("focusin event", async () => {
533+
outer.addEventListener("focusin", () => {
534+
catched = "outer";
535+
});
536+
inner.dispatchEvent(events.focusin_event());
537+
await utils.timeout(1);
538+
expect(catched).toBe("outer");
539+
});
540+
541+
it("focusout event", async () => {
542+
outer.addEventListener("focusout", () => {
543+
catched = "outer";
544+
});
545+
inner.dispatchEvent(events.focusout_event());
546+
await utils.timeout(1);
547+
expect(catched).toBe("outer");
548+
});
549+
532550
it("input event", async () => {
533551
outer.addEventListener("input", () => {
534552
catched = "outer";

0 commit comments

Comments
 (0)