2.0.0 β’ Published 12 months ago
autocomplete-react-minimalist v2.0.0
AutoComplete React Component
Overview
This AutoComplete
React component enhances user input experience by providing real-time suggestions as the user types. It is minimalist, highly customizable and easy to integrate into your React projects.
Features
- π Dynamic Filtering: Filters options based on user input.
- β¨ Customizable Styles: Supports BEM methodology for easy styling.
- π Option Restriction: Option to restrict input to the provided options.
- π Updatable: Responds to changes with an
onChange
handler.
Installation
npm install autocomplete-react-minimalist
Usage
import Autocomplete from "autocomplete-react-minimalist";
const options = [
{ label: "Afghanistan", key: "AF" },
{ label: "Γ
land Islands", key: "AX" },
{ label: "Albania", key: "AL" },
{ label: "Algeria", key: "DZ" },
{ label: "American Samoa", key: "AS" },
{ label: "Andorra", key: "AD" },
];
const MyComponent = () => {
return (
<Autocomplete
inputKey="my-autocomplete"
placeholder="Type to search..."
listToFilter={options}
modifierClass=""
isRestrictedToOption={true}
onChange={(value) => console.log(value)}
notFoundMessage="No results found."
/>
);
};
Props
- π
inputKey
(string): Unique key for the input element. - π¬
placeholder
(string): Placeholder text for the input field. - π
listToFilter
(array): Array of objects withkey
andlabel
to filter. Inside sample you can find a json example. - π¨
modifierClass
(string): Custom CSS class for styling. - π
initValue
(string): Initial value of the input. - π
isRestrictedToOption
(boolean): Restricts input to the provided options. - π
onChange
(function): Callback function for input change. Receives the key and value for the selected option. - π
notFoundMessage
(string): If this is defined, It'll show this message when no options are found instead of closing the dropdown.
Styles
Use BEM conventions for custom styling. We're working to support tailwind.
Component | Class |
---|---|
Input | autocomplete__input |
List Container | autocomplete__search |
List Item (option) | autocomplete__search-item |
Collaborate
Feel free to open an issue or submit a pull request. We're open to suggestions and improvements. Before any contribution, please format the code as the project with npm run format.