reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Add autocomplete support to input component

Open FHU-yezi opened this issue 3 years ago β€’ 0 comments

When I go through the documentation of Input component, I noticed that we should support autocomplete feature.

Just googled and found chakra-ui-simple-autocomplete, a Chakra UI related library licensed in MIT.

Copy the example code there:

import { Autocomplete, Option } from 'chakra-ui-simple-autocomplete';

const options = [
  { value: 'javascript', label: 'Javascript' },
  { value: 'chakra', label: 'Chakra' },
  { value: 'react', label: 'React' },
  { value: 'css', label: 'CSS' },
];

const AutocompleteWrapper = () => {
  const [result, setResult] = React.useState<Option[]>([]);

  return (
      <Box maxW="md">
        <Autocomplete
          options={options}
          result={result}
          setResult={(options: Option[]) => setResult(options)}
          placeholder="Autocomplete"
        />
      </Box>
  );
};

So we should include this in our front-end build, and add some props as well as an event linstener, maybe called on_autocomplete_selected.

By the way, we need to give a chance that user can change options dynamicly, so we can query the database and change them, sounds like search component which we are working on.

FHU-yezi avatar Jan 10 '23 08:01 FHU-yezi