Commit 05aaa99e authored by Shane Eckenrode's avatar Shane Eckenrode

fix(browser): Add explicit change detector check when focusing inputs to...

fix(browser): Add explicit change detector check when focusing inputs to prevent changedAfterChecked errors on matInput's
parent f90667e2
Pipeline #112456 passed with stages
in 3 minutes and 58 seconds
import { isPlatformBrowser } from '@angular/common';
import { AfterViewInit, Directive, ElementRef, Inject, PLATFORM_ID } from '@angular/core';
import { AfterViewInit, ChangeDetectorRef, Directive, ElementRef, Inject, PLATFORM_ID } from '@angular/core';
@Directive({
selector: '[utAutoFocus]'
})
export class FocusDirective implements AfterViewInit {
constructor(private element: ElementRef, @Inject(PLATFORM_ID) private platform: Object) {}
constructor(
private element: ElementRef,
@Inject(PLATFORM_ID) private platform: Object,
private changeDetectorRef: ChangeDetectorRef
) {}
public ngAfterViewInit(): void {
if (isPlatformBrowser(this.platform)) {
this.element.nativeElement.focus();
this.changeDetectorRef.detectChanges();
}
}
}
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 17 issues

    • 4 major
    • 🔽 7 minor
    • 6 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Remove this useless assignment to variable "result". 📘
    2. Remove this useless assignment to variable "complete". 📘
    3. Remove this useless assignment to variable "loadResult". 📘
    4. Remove this useless assignment to variable "loadComplete". 📘
    5. 🔽 Add an "alt" attribute to this image. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    10. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    • ... 7 more
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment