question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<AutoCompleteInput> should be able to access the value but render the label instead

See original GitHub issue

  let cats = [
    { value: 'CAT_1', label: 'Kitty 1' },
    { value: 'CAT_2', label: 'Kitty 2'},
  ];

  return
  <AutoComplete openOnFocus suggestWhenEmpty rollNavigation>
    <AutoCompleteInput variant="ghost" bgColor="transparent" />

    <AutoCompleteList fontStyle="normal">
      {cats.map((cat) => (
        <AutoCompleteItem
          key={cat.value}
          value={cat.value}
          textTransform="capitalize"
        >
          {cat.label}
        </AutoCompleteItem>
      ))}
    </AutoCompleteList>
  </AutoComplete>
}

Package version “@choc-ui/chakra-autocomplete”: “^4.3.4”,

In the above example, I want the AutoCompleteList items to show up options like "Kitty 1", “Kitty 2” and so on. Now when I select any option, the value that gets set in the <AutoCompleteInput> is CAT_1 whereas I wanted “Kitty 1” to get set because that is what I chose. The only way to get around this is to make sure the value and label (child of <AutoCompleteItem>) is set as the same thing i.e. cat.label in this case, but this breaks the point of having the ability to pass a different value and child to <AutoCompleteItem>

The behaviour that is expected is similar to how any <Menu> component would work.

tldr: the value maintained internally and the value displayed/rendered should be different for the input box.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
anubra266commented, Aug 10, 2021

@guilnorth the AutoComplete component actually has a filter prop, it accepts a function that you can use to acces the value passed to the items, and filter as you wish. It provides, the inputQuery, the itemValue and the itemLabel

0reactions
guilnorthcommented, Aug 11, 2021

Hi @guilnorth, could you explain what you mean by multiple keys to filter?

~~Maybe the possibility to pass a custom filter, for example if i need to filter by name or by email. Is a very common use case, like https://react-select.com/advanced#custom-filter-logic.~~

@icy-meteor there’s a label prop in the latest version.

Great, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The AutocompleteInput Component - React-admin - Marmelab
By default, react-admin uses the recordRepresentation function to display the record label. But if you set the optionText prop, react-admin will use it...
Read more >
Getting the value in the React material-UI Autocomplete
For example, I want to use the onChange prop to this so that I can make some actions based on the selection. I...
Read more >
Autocomplete Input - FormKit
A Pro input that allows users to search and select from a customizable options list. Supports single and multi-value selections.
Read more >
Implementing autocompletion in a React Material UI ...
In this article, we will learn how to implement autocompletion in a React Material UI application. Autocomplete fields give a smaller list ...
Read more >
How to Use The Autocomplete Component in Material-UI
We will set the selectedTeam variable to be the option value. <Autocomplete id="nba teams" options={nbaTeams} renderInput={params => ( < ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found