【发布时间】:2021-09-02 09:51:43
【问题描述】:
我在 Material-UI 自动完成中有一系列电影,我想将我最喜欢的电影 - 办公空间 - 添加到这个数组中。有没有办法给这部电影自定义样式,让它有文字color: primary?
export default function Playground() {
const favMovie = {title: "Office Space", year: 1999}
top100Films.push(favMovie)
const defaultProps = {
options: top100Films,
getOptionLabel: (option) => option.title
};
const [movies, setMovies] = useState([]);
return (
<div style={{ width: 300 }}>
<Autocomplete
{...defaultProps}
id="select-on-focus"
selectOnFocus
renderInput={(params) => (
<TextField {...params} label="movies" margin="normal" />
)}
onChange={(e, movie) => {
if (movie) {
setMovies([...movies, movie.title]);
}
}}
/>
</div>
);
}
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ title: "The Shawshank Redemption", year: 1994 },
{ title: "The Godfather", year: 1972 },
...,
]
【问题讨论】:
标签: reactjs autocomplete material-ui