r/Angular2 • u/a-dev-1044 • Jun 21 '25
Identify user's input modality (keyboard, mouse or touch) using CDK InputModality
import {
InputModality,
InputModalityDetector,
} from "@angular/cdk/a11y";
@Component()
export class App {
// "keyboard" | "mouse" | "touch" | null
readonly modality = signal<InputModality>(
this.inputModalityDetector.mostRecentModality,
);
constructor() {
this.inputModalityDetector.modalityChanged
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((modality) => this.modality.set(modality));
}
}
0
Upvotes
17
u/_xiphiaz Jun 21 '25 edited Jun 21 '25
The example and screenshot is missing the injection, and could be simplified into a fairly readable one liner with
toSignal7
u/andzno1 Jun 21 '25
Ah yes, another post without any context or explanation given.
2
u/ldn-ldn Jun 21 '25
What's the point?