Below you can find an example from the MUI docs on Autocomplete where I've passed a link to google, prior to the options list. However, I can't click that option, the event target is just the MuiAutocomplete, rather than the <a>
I'm passing.
import React from "react";
import TextField from "@material-ui/core/TextField";
import Paper from "@material-ui/core/Paper";
import Autocomplete from "@material-ui/lab/Autocomplete";
const Link = ({ children }) => (
<Paper>
<a href="https://www.google.com/" rel="nofollow" target="_blank">
Go to Google
</a>
{children}
</Paper>
);
export default function ComboBox() {
return (
<Autocomplete
id="combo-box-demo"
options={top100Films}
getOptionLabel={option => option.title}
style={{ width: 300 }}
renderInput={params => (
<TextField {...params} label="Combo box" variant="outlined" fullWidth />
)}
PaperComponent={Link}
/>
);
}
https://codesandbox.io/s/material-demo-egi6p
Interestingly, passing open to the autocomplete
<Autocomplete
open // add this prop
id="combo-box-demo"
options={top100Films}
allows this to work as expected.
Currently, I'm using a onMouseDown to make this work but feel this is possibly a bad solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…