Skip to content

Commit

Permalink
refactor(core): Add mouseover to hover dom triggers (angular#58197)
Browse files Browse the repository at this point in the history
Unfortunately mouseenter is a synthetic event, meaning it does not bubble in the same ways. So mouseover needs to be included in this list in order to get proper browser replayability of the mouse hovering events.

PR Close angular#58197
  • Loading branch information
thePunderWoman authored and AndrewKushnir committed Oct 14, 2024
1 parent d8b5f4e commit 9224f9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/defer/dom_triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const interactionTriggers = new WeakMap<Element, DeferEventEntry>();
const viewportTriggers = new WeakMap<Element, DeferEventEntry>();

/** Names of the events considered as interaction events. */
const interactionEventNames = ['click', 'keydown'] as const;
export const interactionEventNames = ['click', 'keydown'] as const;

/** Names of the events considered as hover events. */
const hoverEventNames = ['mouseenter', 'focusin'] as const;
export const hoverEventNames = ['mouseenter', 'mouseover', 'focusin'] as const;

/** `IntersectionObserver` used to observe `viewport` triggers. */
let intersectionObserver: IntersectionObserver | null = null;
Expand Down
23 changes: 18 additions & 5 deletions packages/core/test/acceptance/defer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3027,8 +3027,9 @@ describe('@defer', () => {
fixture.detectChanges();
flush();

expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith('mouseenter', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('mouseover', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('focusin', jasmine.any(Function), jasmine.any(Object));
}));

Expand Down Expand Up @@ -3062,8 +3063,9 @@ describe('@defer', () => {
fixture.componentInstance.renderBlock = false;
fixture.detectChanges();

expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith('mouseenter', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('mouseover', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('focusin', jasmine.any(Function), jasmine.any(Object));
}));

Expand Down Expand Up @@ -3098,8 +3100,9 @@ describe('@defer', () => {
fixture.componentInstance.renderBlock = false;
fixture.detectChanges();

expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith('mouseenter', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('mouseover', jasmine.any(Function), jasmine.any(Object));
expect(spy).toHaveBeenCalledWith('focusin', jasmine.any(Function), jasmine.any(Object));
}));

Expand Down Expand Up @@ -4021,25 +4024,35 @@ describe('@defer', () => {
fixture.detectChanges();

// Verify that trigger element is cleaned up.
expect(triggerSpy).toHaveBeenCalledTimes(2);
expect(triggerSpy).toHaveBeenCalledTimes(3);
expect(triggerSpy).toHaveBeenCalledWith(
'mouseenter',
jasmine.any(Function),
jasmine.any(Object),
);
expect(triggerSpy).toHaveBeenCalledWith(
'mouseover',
jasmine.any(Function),
jasmine.any(Object),
);
expect(triggerSpy).toHaveBeenCalledWith(
'focusin',
jasmine.any(Function),
jasmine.any(Object),
);

// Verify that prefetch trigger element is cleaned up.
expect(prefetchSpy).toHaveBeenCalledTimes(2);
expect(prefetchSpy).toHaveBeenCalledTimes(3);
expect(prefetchSpy).toHaveBeenCalledWith(
'mouseenter',
jasmine.any(Function),
jasmine.any(Object),
);
expect(prefetchSpy).toHaveBeenCalledWith(
'mouseover',
jasmine.any(Function),
jasmine.any(Object),
);
expect(prefetchSpy).toHaveBeenCalledWith(
'focusin',
jasmine.any(Function),
Expand Down

0 comments on commit 9224f9b

Please sign in to comment.