Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 164x 164x 164x 164x 1x 1x 1x 1x 1x 164x 164x 164x 164x 164x 164x 164x 164x 3594x 3594x 164x 164x 1x 1x 134x 134x 134x 134x 134x 134x 134x 134x 1x 1x 134x 2984x 2437x 547x 547x 2984x 134x 134x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 143x 1x 1x 143x 143x 143x 143x 1x 1x 1x 91x 91x 91x 6x 6x 91x 91x 1x 1x 143x 143x 143x 143x 1x 1x 1x 1x 1x | import { AfterViewInit, Component, ComponentRef, ElementRef, EventEmitter, HostBinding, HostListener, Input, Output, ViewChild, ViewContainerRef, ViewEncapsulation, } from '@angular/core'; import { getKeyboardFocusableElements } from '../../../utils/internal-utils'; import { ModalConfig } from '../modal-overlay-container.service'; export class DialogOverlayRef { public readonly onClosed: EventEmitter<void> = new EventEmitter<void>(); public readonly onCancel: EventEmitter<void> = new EventEmitter<void>(); private focusNode?: HTMLElement; private _disabledElements: Map<Element, string | null> = new Map< Element, string | null >(); constructor() { if ( document.activeElement !== null && document.activeElement instanceof HTMLElement ) { this.focusNode = document.activeElement; } getKeyboardFocusableElements(document.body).forEach(el => { this._disabledElements.set(el, el.getAttribute('tabindex')); el.setAttribute('tabindex', '-1'); }); } public close(): void { this.resetTabIndex(); this.onClosed.next(); setTimeout(() => { this.focusNode?.focus(); }); } private resetTabIndex() { this._disabledElements.forEach((v, k) => { if (v === null) { k.removeAttribute('tabindex'); } else { k.setAttribute('tabindex', v); } }); } } @Component({ selector: 'gc-dialog-modal-overlay-container', template: ` <dialog #dialog [attr.aria-label]="labelledby ? null : label" [attr.aria-labelledby]="labelledby" [attr.aria-describedby]="describedby" [attr.role]="_role" class="gc-dialog-modal-overlay-container" (close)="handleDialogClose()" (cancel)="handleCancel($event)" > <ng-container #container /> </dialog>`, styleUrls: ['./dialog-modal-overlay-container.css'], // eslint-disable-next-line @angular-eslint/use-component-view-encapsulation encapsulation: ViewEncapsulation.None, standalone: false, }) export class DialogModalOverlayContainerComponent implements AfterViewInit { @HostBinding('class.gc-modal-error') public _errorType = false; @HostBinding('class.gc-modal-inactive') public _inactive = false; @Input() public label?: string; @Input() public describedby: string | null = null; @Input() public labelledby: string | null = null; @Output() public readonly onClose: EventEmitter<void> = new EventEmitter<void>(); @Output() public readonly onCancel: EventEmitter<void> = new EventEmitter<void>(); @ViewChild('container', { read: ViewContainerRef }) private container?: ViewContainerRef; @ViewChild('dialog') private dialog?: ElementRef<HTMLDialogElement>; @Input() public set component(c: ComponentRef<unknown>) { this.container?.clear(); setTimeout(() => { this.container?.insert(c.hostView); }); } protected _role: 'alertdialog' | null = null; private focusNode?: HTMLElement; constructor(config: ModalConfig) { this._errorType = config.type === 'error'; this._role = config.variant === 'alertdialog' ? 'alertdialog' : null; this.focusNode = document.activeElement as HTMLElement; } @HostListener('keydown', ['$event']) public handleKeyDown(evt: KeyboardEvent) { // We suppress the possibility for the browser to emit an Dialog-CancelEvent because Chrome/Edge // does not send such an event if one presses Escape multiple times - see https://issues.chromium.org/issues/41491338 if (evt.key === 'Escape') { evt.preventDefault(); this.onCancel.emit(); } } ngAfterViewInit(): void { if (this.dialog) { this.dialog.nativeElement.showModal(); } } protected handleDialogClose(): void { this.onClose.emit(); this.focusNode?.focus(); } protected handleCancel(evt: Event) { console.warn( 'We should not have reached this point because we handle the key-event.', ); // As we canceled the Key-Event for Escape we should not have been called. Still as a safeguard // we cancel the Cancel-Event evt.preventDefault(); } } |