MCPcopy Create free account
hub / github.com/angular/components / constructor

Method constructor

src/material/sidenav/drawer.ts:362–399  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

360 private _changeDetectorRef = inject(ChangeDetectorRef);
361
362 constructor() {
363 this.openedChange.pipe(takeUntil(this._destroyed)).subscribe((opened: boolean) => {
364 if (opened) {
365 this._elementFocusedBeforeDrawerWasOpened = this._doc.activeElement as HTMLElement;
366 this._takeFocus();
367 } else if (this._isFocusWithinDrawer()) {
368 this._restoreFocus(this._openedVia || 'program');
369 }
370 });
371
372 /**
373 * Listen to `keydown` events outside the zone so that change detection is not run every
374 * time a key is pressed. Instead we re-enter the zone only if the `ESC` key is pressed
375 * and we don't have close disabled.
376 */
377 this._eventCleanups = this._ngZone.runOutsideAngular(() => {
378 const renderer = this._renderer;
379 const element = this._elementRef.nativeElement;
380
381 return [
382 renderer.listen(element, 'keydown', (event: KeyboardEvent) => {
383 if (event.keyCode === ESCAPE && !this.disableClose && !hasModifierKey(event)) {
384 this._ngZone.run(() => {
385 this.close();
386 event.stopPropagation();
387 event.preventDefault();
388 });
389 }
390 }),
391 renderer.listen(element, 'transitionend', this._handleTransitionEvent),
392 renderer.listen(element, 'transitioncancel', this._handleTransitionEvent),
393 ];
394 });
395
396 this._animationEnd.subscribe(() => {
397 this.openedChange.emit(this.opened);
398 });
399 }
400
401 /**
402 * Focuses the first element that matches the given selector within the focus trap.

Callers

nothing calls this directly

Calls 6

_takeFocusMethod · 0.95
_isFocusWithinDrawerMethod · 0.95
_restoreFocusMethod · 0.95
closeMethod · 0.95
hasModifierKeyFunction · 0.90
listenMethod · 0.80

Tested by

no test coverage detected