EDIT:
After looking at few other libraries, I found out react-datalist-input provides the easiest way to interact with datalists in react, style and functionality alike.
You can access styles via
.datalist-input
A simple code snippet below:
const DataListWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
margin-top: 6px;
.datalist-input {
width: 50%;
color: black;
}
`;
const SomeComponent = () => {
return (
<DataListWrapper>
<ReactDataList
forcePoly
placeholder="Search Something..."
list="my_list"
options={options}
onOptionSelected={(e) => foo(e)}
/>
</DataListWrapper>
);
};
Old answer:
(note: react-datalist
is not being maintained and some of its dependencies are deprecated)
When working with react, you can style the options and the datalist itself using
react-datalist
https://www.npmjs.com/package/react-datalist
You can access these using CSS or styled-components
.react-datalist
.react-datalist-option
Here is a simple code snippet using styled-components:
const DataListWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
margin-top: 6px;
.datalist-input {
width: 50%;
color: black;
}
`;
const SomeComponent = () => {
return (
<>
<DataListWrapper>
<DataListInput
placeholder="Search Something..."
items={items}
onSelect={DoSomething}
/>
</DataListWrapper>
</>
);
};