Skip to content

Commit

Permalink
feat: Add window events "pagehide" / "pageshow" (#1308)
Browse files Browse the repository at this point in the history
MDN documentation at:

https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event

By adding these events, it allows library users to use the familiar
fireEvent & friends in their test environments to verify pagehide and
pageshow behavior.

Co-authored-by: Matan Borenkraout <Matanbobi@gmail.com>
  • Loading branch information
jdufresne and MatanBobi authored Apr 29, 2024
1 parent 47fe879 commit 56543d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const eventTypes = [
elementType: 'img',
},
{
type: '',
events: ['offline', 'online'],
type: 'Window',
events: ['offline', 'online', 'pageHide', 'pageShow'],
elementType: 'window',
},
{
Expand Down
8 changes: 8 additions & 0 deletions src/event-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ export const eventMap = {
EventType: 'Event',
defaultInit: {bubbles: false, cancelable: false},
},
pageHide: {
EventType: 'PageTransitionEvent',
defaultInit: {bubbles: true, cancelable: true},
},
pageShow: {
EventType: 'PageTransitionEvent',
defaultInit: {bubbles: true, cancelable: true},
},
}

export const eventAliasMap = {
Expand Down
2 changes: 2 additions & 0 deletions types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export type EventType =
| 'lostPointerCapture'
| 'offline'
| 'online'
| 'pageHide'
| 'pageShow'

export type FireFunction = (
element: Document | Element | Window | Node,
Expand Down

0 comments on commit 56543d5

Please sign in to comment.