Skip to content

Instantly share code, notes, and snippets.

@madan712
Created April 23, 2023 13:44
Show Gist options
  • Save madan712/1a8a07c8d4b55ae5c528e3e39d2aba26 to your computer and use it in GitHub Desktop.
Save madan712/1a8a07c8d4b55ae5c528e3e39d2aba26 to your computer and use it in GitHub Desktop.
React auto suggest input, Auto complete input box, React input suggestion, Simple auto suggest input, User input auto suggest, Dynamic input suggestion, React search input, Instant search suggestion, Efficient auto complete input, React auto fill input
import React, { useState } from 'react';
import AutoSuggestInput from 'autosuggest-input-box';
import { Box, Control, Label, Row } from './AutoSuggestInputStyle';
const countries = [
'China',
'India',
'United States',
'Indonesia',
'Pakistan',
'Brazil',
'Nigeria',
'Bangladesh',
'Russia',
'Mexico',
'Japan',
'Ethiopia',
'Philippines',
'gypt',
'Vietnam',
'DR Congo',
'Turkey',
'Iran',
'Germany',
'Thailand',
'United Kingdom',
'France',
'Italy',
'Tanzania',
'SouthAfrica',
];
const fruits = [
'Apple',
'Banana',
'Orange',
'Mango',
'Pineapple',
'Grapes',
'Watermelon',
'Kiwi',
'Papaya',
'Strawberry',
'Blueberry',
'Raspberry',
'Blackberry',
'Cherry',
'Peach',
'Pear',
'Plum',
'Fig',
'Guava',
'Avocado',
];
const colors = [
'Red',
'Blue',
'Green',
'Yellow',
'Orange',
'Purple',
'Pink',
'Brown',
'Black',
'White',
'Gray',
];
const AutoSuggestInputDemo: React.FC = () => {
const [value, setValue] = useState<string>('');
const onChange = (input: string) => {
setValue(input);
console.log(input);
};
return (
<>
<Box>
<Row>
<Label>Country:</Label>
<Control>
<AutoSuggestInput
list={countries}
onChange={onChange}
/>
</Control>
</Row>
<Row>
<Label>Fruits:</Label>
<Control>
<AutoSuggestInput
list={fruits}
onChange={onChange}
placeholder="Fruits"
inputStyle={{
width: '200px',
height: '40px',
border: '2px solid red',
borderRadius: '5px',
}}
itemHoverStyle={{
backgroundColor: '#FFFFCC',
}}
/>
</Control>
</Row>
<Row>
<Label>Colors:</Label>
<Control>
<AutoSuggestInput
list={colors}
onChange={onChange}
placeholder="Colors"
inputStyle={{
width: '200px',
border: '1px solid blue',
backgroundColor: '#FFC0CB',
borderRadius: '5px',
}}
listStyle={{
width: '150px',
color: '#1569C7',
padding: '0px 0px',
zIndex: '999',
}}
itemStyle={{
padding: '10px',
backgroundColor: '#F0FFFF',
border: '1px solid #d4d4d4',
borderTop: 'none',
borderRadius: '5px',
}}
itemHoverStyle={{
padding: '10px',
backgroundColor: '#E6E6FA',
border: '1px solid #d4d4d4',
borderTop: 'none',
borderRadius: '5px',
}}
/>
</Control>
</Row>
</Box>
</>
);
};
export default AutoSuggestInputDemo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment