Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

12 changes: 0 additions & 12 deletions .eslintrc

This file was deleted.

18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [18]
node: [24]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install dependencies
run: yarn
run: npm ci

- name: "Test: typings"
run: "yarn run test:typings"
run: "npm run test:typings"

- name: "Test: TS/JS linting + formatting"
run: "yarn run test:lint"
run: "npm run test:lint"

- name: "Build"
run: yarn build
run: npm run build

- name: "Publint"
run: yarn publint
run: npm run publint

- name: "Are the types wrong?"
run: yarn attw -P
run: npm run attw -P
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI runs npm run attw -P, but -P won’t be forwarded to the script without -- (and the attw script already hardcodes -P). Also @arethetypeswrong/cli in the updated lockfile declares engines.node >= 20, while this workflow pins Node 18, so the attw step is likely to fail at runtime. Consider updating the workflow matrix to Node 20+ and invoking the script as npm run attw (or npm run attw -- -P if you remove -P from the script).

Copilot uses AI. Check for mistakes.
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true
}
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ Get the eventKey keyCode and log it on `keyUp` on the window element
<KeyBinding onKey={ (e) => { console.log(e.keyCode) } } type='keyup' target={ window } />
```

Scope the listener to a container element via a React ref (only fires when focus is inside the container)
``` JSX
const containerRef = useRef(null);

<div ref={containerRef}>
<KeyBinding onKey={ (e) => { console.log(e.keyCode) } } target={ containerRef } />
</div>
```

Have a look at options.

### Options
Expand All @@ -32,7 +41,7 @@ All properties except `onKey` are optional.
|----------------------------------|----------------------------------------------------------------------------------------------------------------------|---------------|
| `onKey` (required) | the function executed after a key event | n/a |
| `type` | keyup or keydown | `'keydown'` |
| `target` | the element you want to attach the event to, it can be an **existing** DOM element or a CSS selector (in that case, you will need to add a `tabIndex='0'` to your element, otherwise the event won't be caught) | `document` |
| `target` | the element you want to attach the event to: an **existing** DOM element, a CSS selector (you will need to add `tabIndex='0'` to your element, otherwise the event won't be caught), or a **React ref** (`RefObject<HTMLElement>`) — if a ref is passed and `.current` is `null`, the listener is silently skipped | `document` |
| `preventInputConflict` | prevent onKey from firing if you have an onChange on an input, a textarea or a select | `false` |
| `preventContentEditableConflict` | prevent onKey from firing if the user is editing the DOM via contenteditable="true", usually used by WYSIWYG editors | `false` |
| `preventDefault` | prevent event default | `false` |
Expand Down
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
"linter": {
"enabled": true,
"rules": {
Expand All @@ -23,6 +23,6 @@
}
},
"files": {
"ignore": ["node_modules", "dist"]
"includes": ["**", "!**/node_modules", "!**/dist"]
}
}
Loading