Skip to content

Commit fe7227b

Browse files
committed
adds datalist match algorithm to README as an example (#22)
1 parent 5f58ed8 commit fe7227b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const YourComponent = ({ myValues }) => {
125125
- currentInput: String, the current user input typed into the input field
126126
- item: Object, the item of the items array (with key and label properties)
127127

128-
- Default:
128+
- Default match function:
129129

130130
```javascript
131131
/**
@@ -134,12 +134,16 @@ const YourComponent = ({ myValues }) => {
134134
* @param item (one item of the items array)
135135
* @returns {boolean}
136136
*/
137-
match = (currentInput, item) => {
138-
return (
139-
item.label.substr(0, currentInput.length).toUpperCase() ===
140-
currentInput.toUpperCase()
141-
);
142-
};
137+
const match = (currentInput, item) =>
138+
item.label.substr(0, currentInput.length).toUpperCase() ===
139+
currentInput.toUpperCase();
140+
```
141+
142+
- If you are looking to have the same behavior as the HTML element [datalist](https://developer.mozilla.org/de/docs/Web/HTML/Element/datalist), use a match function like follows:
143+
144+
```javascript
145+
const match = (currentInput, item) =>
146+
item.label.toLowerCase().includes(currentInput.toLowerCase());
143147
```
144148

145149
### <a name="markdown-header-onDropdownOpen"></a>onDropdownOpen

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)