在Material-ui中隐藏onFocus上的自动完成标签,可以通过以下步骤实现:
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
const [open, setOpen] = useState(false);
<TextField
onFocus={() => setOpen(true)}
...
/>
<Autocomplete
open={open}
...
/>
完整的代码示例:
import React, { useState } from 'react';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
const MyComponent = () => {
const [open, setOpen] = useState(false);
return (
<Autocomplete
open={open}
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
options={[]}
renderInput={(params) => (
<TextField
{...params}
onFocus={() => setOpen(true)}
label="Search"
/>
)}
/>
);
};
export default MyComponent;
这样,在Material-ui中就可以隐藏onFocus上的自动完成标签。
领取专属 10元无门槛券
手把手带您无忧上云