Skip to content

Commit cca1741

Browse files
📖 Other docs updates and test fixups
1 parent 3b00c09 commit cca1741

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

docs/with-keypress.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ const MyButton = () => {
3333
};
3434
```
3535

36+
Although this library doesn't export handlers for specific keys, you could use this method to build out your own suite of key event handlers:
37+
38+
```js
39+
// /utils/keyboard.js
40+
const withEscapeKeyPress = withKeyPress('Escape');
41+
const withEnterKeyPress = withKeyPress('Enter');
42+
const withTabKeyPress = withKeyPress('Tab');
43+
const withShiftKeyPress = withKeyPress('Shift');
44+
// ...etc
45+
```
46+
47+
3648
[![Edit with-keypress (React)](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/with-keypress-react-9344c?fontsize=14&hidenavigation=1&theme=dark)

docs/with-target-value.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### withTargetValue
22

3-
Calls your provided event handler function with `event.target.value` as the first value (if it exists).
3+
Calls your provided event handler function with `event.target.value` as the first value (if it exists). Passes the `event` along as the second argument in case you need it.
44

55
**Vanilla**
66

@@ -22,14 +22,12 @@ myInputNode.addEventListener(
2222
import React, { Component } from "react";
2323
import { withTargetValue } from "browser-event-utils";
2424

25-
class MyInput extends Component {
26-
handleChange = withTargetValue((value, event) => {
27-
console.log(`Value changed! ${value}`);
28-
});
25+
const handleChange = withTargetValue((value, event) => {
26+
console.log(`Value changed! ${value}`);
27+
});
2928

30-
render() {
31-
return <input onChange={this.handleChange} />;
32-
}
29+
function MyInput() {
30+
return <input type="text" onChange={handleChange} />;
3331
}
3432
```
3533

src/helpers/__tests__/with-target.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ describe('withTarget', () => {
1010
};
1111
const mock = jest.fn();
1212
withTarget(mock)(mockEvent);
13-
expect(mock).toHaveBeenCalledWith(mockEvent);
13+
expect(mock).toHaveBeenCalledWith(mockEvent.target, mockEvent);
1414
});
1515
});

0 commit comments

Comments
 (0)