我正在使用带有TextField的Material UI(MUI)Autocomplete,我想实现一种特定的行为。目前,当我单击搜索栏时,占位符文本会移动到TextField的顶部。但是,我想在单击搜索栏时完全删除占位符文本。
这是我当前的代码:
import * as React from 'react';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
const top100Cars = [
{ label: 'Toyota' },
{ label: 'Ford' },
{ label: 'Chevrolet' },
{ label: 'Tesla' },
{ label: 'Honda' },
{ label: 'BMW' },
{ label: 'Audi' },
{ label: 'Mercedes-Benz' },
{ label: 'Ferrari' },
{ label: 'Porsche' },
{ label: 'Lamborghini' },
{ label: 'Nissan' },
{ label: 'Volkswagen' },
{ label: 'Mazda' },
{ label: 'DeLorean' },
{ label: 'Dodge' },
];
export default function searchBar() {
return (
<Autocomplete
disablePortal
id="combo-box-demo"
options={top100Cars}
sx={{
width: 254, backgroundColor: 'white', borderRadius: 50,
}}
renderInput={(params) => (
<TextField
{...params}
label="ÐаÑка"
size='small'
/>
)}
/>
);
}
现在的情况如下:
我想删除单击文本字段时出现在左上角的占位符文本。我希望这对你有意义!
我尝试过使用各种配置设置InputLabelProps和InputProps属性,但占位符文本仍然保留。单击搜索栏时,如何修改代码以实现删除占位符文本的预期行为?