MCPcopy Index your code
hub / github.com/angular/components / constructor

Method constructor

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

Source from the content-addressed store, hash-verified

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