/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/cdk/menu/event-detection.ts
37 строк
1 KB
Andrew Seguin
refactor: use relative imports within module npm packages (#30588)
12 мар 2025, 00:40
Не верифицирован
12 мар 2025, 00:40
626a465
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {ElementRef} from '@angular/core'; import {ENTER, SPACE} from '../keycodes'; /** Checks whether a keyboard event will trigger a native `click` event on an element. */ export function eventDispatchesNativeClick( elementRef: ElementRef<HTMLElement>, event: KeyboardEvent, ): boolean { // Synthetic events won't trigger clicks. if (!event.isTrusted) { return false; } const el = elementRef.nativeElement; const keyCode = event.keyCode; // Buttons trigger clicks both on space and enter events. if (el.nodeName === 'BUTTON' && !(el as HTMLButtonElement).disabled) { return keyCode === ENTER || keyCode === SPACE; } // Links only trigger clicks on enter. if (el.nodeName === 'A') { return keyCode === ENTER; } // Any other elements won't dispatch clicks from keyboard events. return false; }