Skip to content

Commit

Permalink
fix(docs-infra): only run matchMedia on client
Browse files Browse the repository at this point in the history
Use afterNextRender to avoid running matchMedia on the server
  • Loading branch information
atscott committed Jul 24, 2024
1 parent c2779eb commit 8b942f3
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
EnvironmentInjector,
afterNextRender,
computed,
effect,
ElementRef,
inject,
model,
signal,
Expand Down Expand Up @@ -49,16 +51,27 @@ export const ALL_STATUSES_KEY = 'All';
export default class ApiReferenceList {
private readonly apiReferenceManager = inject(ApiReferenceManager);
filterInput = viewChild.required(TextField, {read: ElementRef});
private readonly injector = inject(EnvironmentInjector);

private readonly allGroups = this.apiReferenceManager.apiGroups;

private filterEffect = effect(() => {
if (matchMedia('(hover: hover) and (pointer:fine)').matches) {
// Lord forgive me for I have sinned
// Use the CVA to focus when https://github.com/angular/angular/issues/31133 is implemented
this.filterInput().nativeElement.querySelector('input').focus();
}
});
constructor() {
effect(() => {
const filterInput = this.filterInput();
afterNextRender(
{
write: () => {
// Lord forgive me for I have sinned
// Use the CVA to focus when https://github.com/angular/angular/issues/31133 is implemented
if (matchMedia('(hover: hover) and (pointer:fine)').matches) {
filterInput.nativeElement.querySelector('input').focus();
}
},
},
{injector: this.injector},
);
});
}

query = signal('');
includeDeprecated = signal(false);
Expand Down

0 comments on commit 8b942f3

Please sign in to comment.