Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
react-datalist-input
Advanced tools
This package provides a react component as follows: an input field with a drop down menu to pick a possible option based on the current input.
This package provides a single react component.
The component contains an input field with a drop down menu to pick a possible option based on the current input as a react component.
Have a look at w3schools.com to see how you can do something similar with pure html, css, and js.
For more information about react and the ecosystem see this guide.
Check it out on my personal website!
Feel free to get inspired and more importantly please provide your feedback on structure and style.
npm install react-datalist-input --save
import DataListInput from 'react-datalist-input';
/**
* OPTIONAL, this packages comes with a simple default label matching function
* but feel free to create your own match algorithm if you want to do so
* @param {String} currentInput (the current user input)
* @param {object} item (one item of the items array)
* @returns {boolean}
*/
matchCurrentInput = (currentInput, item) => {
const yourLogic = item.someAdditionalValue;
return (yourLogic.substr(0, currentInput.length).toUpperCase() === currentInput.toUpperCase());
};
/**
* your callback function gets called if the user selects one option out of the drop down menu
* @param selectedItem object (the selected item / option)
* @returns {*}
*/
onSelect = (selectedItem) => {
this.doSomething(selectedItem);
};
render() {
// the array you want to pass to the react-data-list component
// each element at least needs a key and a label
const items = myValues.map((item, i) => {
return {
// what to show to the user
label: item.id + ": " + item.name,
// key to identify the item within the array
key: item.id,
// feel free to add your own app logic to access those properties in the onSelect function
someAdditionalValue: item.someAdditionalValue,
// or just keep everything
...item,
}
});
return(
<div>
<DataListInput
placeholder={"Select an option from the drop down menu..."}
items={items}
onSelect={this.onSelect}
match={this.matchCurrentInput}
/>
</div>
);
Prop | Type | Required/Optional | Default Value |
---|---|---|---|
items | array | required | - |
onSelect | function | required | - |
match | function | optional | required |
onDropdownOpen | function | optional | - |
onDropdownClose | function | optional | - |
placeholder | string | optional | '' |
itemClassName | string | optional | - |
activeItemClassName | string | optional | - |
inputClassName | string | optional | - |
dropdownClassName | string | optional | - |
requiredInputLength | number | optional | 0 |
clearInputOnSelect | boolean | optional | false |
suppressReselect | boolean | optional | true |
dropDownLength | number | optional | infinite |
initialValue | string | optional | - |
debounceTime | number | optional | 0 |
debounceLoader | string | optional | 'Loading...' |
onInput | function | optional | - |
Pass a match function as stated above for creating your own matching algorithm for the autocomplete functionality.
Parameter: (currentInput, item)
Default:
/**
* default function for matching the current input value (needle) and the values of the items array
* @param currentInput String (the current user input)
* @param item (one item of the items array)
* @returns {boolean}
*/
match = (currentInput, item) => {
return item.label.substr(0, currentInput.length).toUpperCase() === currentInput.toUpperCase();
};
requiredInputLength=3
, only if the user input is longer than 2 characters, the dropdown menu will appear.dropDownLength
matches in the dropdown. Useful if the array is really big.initialValue={'hello world'}
will print hello world
into the input field on first render.debounceTime
to define a debounce timeout time (in milliseconds) before the matching algorithm should be calleddebounceTime={1000}
will call the matching algorithm one second after the last user inputitems
is very large and/or the match
-algorithm is doing some heavier operationsdebounceTime
may improve the user experience by reducing lag times as it reduces the calls to the matching and rendering of the dropdown.debounceTime={3000}
or higher, you might want to consider using another package / user input instead. Think about a "search/look-up"-button next to your input field or even consider running the search functionality in a dedicated backend.FAQs
react-datalist-input provides a React datalist/combobox component called DatalistInput. The component contains an input field with a dropdown menu of suggestions based on the current input.
The npm package react-datalist-input receives a total of 476 weekly downloads. As such, react-datalist-input popularity was classified as not popular.
We found that react-datalist-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.