• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacklok / codegate-ui / 12927693746

23 Jan 2025 10:56AM UTC coverage: 68.996% (-0.6%) from 69.578%
12927693746

Pull #180

github

web-flow
Merge 997393962 into 6da034d9d
Pull Request #180: feat: useKbdShortcuts hook & example implementation

312 of 549 branches covered (56.83%)

Branch coverage included in aggregate %.

8 of 16 new or added lines in 3 files covered. (50.0%)

636 of 825 relevant lines covered (77.09%)

55.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.0
/src/hooks/use-kbd-shortcuts.ts
1
import { useEffect } from "react";
2

3
export function useKbdShortcuts(map: [string, () => void][]) {
4
  return useEffect(() => {
7✔
5
    const documentListener = (e: KeyboardEvent) => {
7✔
NEW
6
      const target = e.target as HTMLElement;
×
NEW
7
      if (
×
8
        target.tagName === "INPUT" ||
×
9
        target.tagName === "TEXTAREA" ||
10
        target.isContentEditable
11
      ) {
NEW
12
        return;
×
13
      }
14

NEW
15
      for (const [key, callback] of map) {
×
NEW
16
        if (e.key.toLowerCase() === key.toLowerCase()) {
×
NEW
17
          e.preventDefault();
×
NEW
18
          e.stopPropagation();
×
NEW
19
          callback();
×
20
        }
21
      }
22
    };
23

24
    document.addEventListener("keydown", documentListener);
7✔
25

26
    return () => {
7✔
27
      document.removeEventListener("keydown", documentListener);
7✔
28
    };
29
  }, [map]);
30
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc