Skip to content

Commit 2f6076c

Browse files
authored
bugfix: malformed casing format (#14)
bugfix: malformed casing format
1 parent 3a353b8 commit 2f6076c

File tree

4 files changed

+132
-43
lines changed

4 files changed

+132
-43
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Click on the hint or use your keyboard **Right** key or **Tab** key(if `allowTab
5959

6060
#### onFill (optional): `(value: string | object)=> void`
6161

62+
#### valueModifier (optional): `(value: string)=> string`
63+
6264

6365
## object option
6466
If you're using objects for your options. object schema is as follows:
@@ -77,6 +79,29 @@ const options = ["orange", "banana", "apple"];
7779
```
7880
...and the input gets filled with *"ORange"*, onFill will still return *"orange"*.
7981

82+
83+
## valueModifier
84+
This prop accepts a function that modifies your input value before it is saved in state.
85+
86+
It is typically useful when you are not setting `e.target.value` directly in state and need to modify the target value to
87+
some other value first before setting it in state.
88+
89+
Example: A case where you need to set the input value to uppercase irrespective of the casing the user types in:
90+
91+
```jsx
92+
const options = ["orange", "banana", "apple"];
93+
94+
const modifyValue = (value: string) => value.toUpperCase();
95+
96+
<Hint options={options} valueModifier={modifyValue}>
97+
<input
98+
value={text}
99+
onChange={e => setText(modifyValue(e.target.value))} />
100+
</Hint>
101+
```
102+
Note: Not setting the `valueModifier` prop in cases like this might result to a malformed hint.
103+
104+
80105
## Duplicate data
81106
If you are using objects for your options, You may have unexpected results if your data options contain objects with duplicate labels. For this reason, it is highly recommended that you pass in objects with unique labels if possible.
82107

0 commit comments

Comments
 (0)