Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

8.0.4 broke element blur in jsDom #482

Closed
RGunning opened this issue Sep 13, 2021 · 2 comments
Closed

8.0.4 broke element blur in jsDom #482

RGunning opened this issue Sep 13, 2021 · 2 comments

Comments

@RGunning
Copy link
Contributor

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Calling blur on a element when in a jsDom environment triggers the angular cdkFocusMonitor

Prior to 8.0.4 calling spectator.blur on a input element with a cdkFocusMonitor listening to the parent element would trigger the subscribe. Current behaviour is that the subscribe is no longer called.

   ngAfterViewInit() {
        this.focusMonitor
            .monitor(this.elementRef, true)
            .pipe(takeUntil(this.ngUnsubscribe$))
            .subscribe((focusOrigin) => {
                if (!focusOrigin) {
                    Promise.resolve().then(() => {
                        this.onTouched();
                        this.cdRef.markForCheck();
                    });
                }
            });
    }

Expected behavior

The blur bubbles in a jsDom environment and trigger the focus monitor subscription.

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem via
https://stackblitz.com or similar (you can use this template as a starting point: https://bit.ly/2zme3bj).

What is the motivation / use case for changing the behavior?

8.0.4 breaks my unit tests, so i can't update to latest spectator.

Environment


Angular version: 11.2.14


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v14.17.3  
- Platform: Mac/Linux 

Others:

Bug introduced by https://github.com/ngneat/spectator/pull/473/files if in a jsDom environment patchElementFocus no longer does anything when it used to call element.focus = () => dispatchFakeEvent(element, 'focus'); element.blur = () => dispatchFakeEvent(element, 'blur');

Re-adding element.blur = () => dispatchFakeEvent(element, 'blur'); is enough to restore old behaviour.

@NetanelBasal
Copy link
Member

@johncrim

RGunning added a commit to RGunning/spectator that referenced this issue Sep 13, 2021
@RGunning RGunning mentioned this issue Sep 13, 2021
3 tasks
@RGunning
Copy link
Contributor Author

duplicate of #477

same fix as there, need to call focus before blur now

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants