TanStack Hotkeys provides the injectHotkeyRecorder API for building shortcut customization UIs in Angular.
import { Component } from '@angular/core'
import {
formatForDisplay,
injectHotkeyRecorder,
} from '@tanstack/angular-hotkeys'
@Component({
standalone: true,
template: `
<button (click)="recorder.isRecording() ? recorder.stopRecording() : recorder.startRecording()">
{{
recorder.isRecording()
? 'Press a key combination...'
: recorder.recordedHotkey()
? formatForDisplay(recorder.recordedHotkey()!)
: 'Click to record'
}}
</button>
@if (recorder.isRecording()) {
<button (click)="recorder.cancelRecording()">Cancel</button>
}
`,
})
export class ShortcutRecorderComponent {
readonly formatForDisplay = formatForDisplay
readonly recorder = injectHotkeyRecorder({
onRecord: (hotkey) => {
console.log('Recorded:', hotkey)
},
})
}
injectHotkeyRecorder({
onRecord: (hotkey) => {},
onCancel: () => {},
onClear: () => {},
})
import { ApplicationConfig } from '@angular/core'
import { provideHotkeys } from '@tanstack/angular-hotkeys'
export const appConfig: ApplicationConfig = {
providers: [
provideHotkeys({
hotkeyRecorder: {
onCancel: () => console.log('Recording cancelled'),
},
}),
],
}