users = [
{
"id": "5d08f94da9d6d25011d55e87",
"name": "Leo"
},
...
]
<Typeahead
labelKey="name"
options={users}
placeholder="Search user..."
onChange={this.handleChangeTy('userSelect')}
/>
You need to add an id to the component, not the options.
@ericgio , can I ask you more clarifications? You can give me an example.
Hi @Angelk90, sure:
<Typeahead
id="my-typeahead-id"
labelKey="name"
options={users}
placeholder="Search user..."
onChange={this.handleChangeTy('userSelect')}
/>
It works like the id on any normal element.
The id prop doesn't actually get passed through to the input. It isn't in the list of props that are passed through:
The id prop doesn't actually get passed through to the input
That's correct. The warning doesn't refer to the input's id; it refers to an id for the typeahead component that is ultimately applied to the menu and used for accessibility. If you need to pass an id to the input itself, you would do that via inputProps.
Why do we need to pass this ID through? The only reason I can think of is for linking the input with the dropdown, but a class name is already automatically generated for this.
What am I missing?
@cameron-martin: It's used for accessibility.
I got that, but what're you meant to link to that ID externally (from outside the component)?
@cameron-martin I'm sorry, but I don't understand your question. You don't need to "link" anything, you just need to provide the id and the accessibility stuff happens internally.
But a random id is generated automatically to use internally, so why do I need to provide one?
The randomly generated id is going away in favor of an explicit, user-defined one. That change is based on what I've seen to be common practice in other libraries, with react-bootstrap being one particularly relevant case.
FYI, the above PR has now landed so should be available in the next version of React :)
Most helpful comment
Hi @Angelk90, sure:
It works like the
idon any normal element.