이미지검색

This commit is contained in:
익희 김 2024-12-23 13:17:45 +09:00
parent fc14716bb3
commit 8980fdcc39

View File

@ -99,6 +99,30 @@ export default function Search({ ...props }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.category, state.subCategory, state.shop]);
const fileInputRef = React.useRef(null);
//
const handleImageSearch = () => {
if (fileInputRef.current) {
fileInputRef.current.click(); //
}
};
//
const handleFileChange = (event) => {
const file = event.target.files?.[0];
if (file) {
console.log('Selected File:', file);
// :
const reader = new FileReader();
reader.onload = () => {
console.log('Image Preview URL:', reader.result);
};
reader.readAsDataURL(file);
}
};
return (
<>
<TextField
@ -143,6 +167,14 @@ export default function Search({ ...props }) {
}
}}
/>
<Button variant='contained' sx={{ width: '100%', borderRadius: 0 }} onClick={handleImageSearch}>이미지 검색</Button>
<input
type="file"
accept="image/*"
ref={fileInputRef}
onChange={handleFileChange}
style={{ display: 'none' }}
/>
<Stack gap={1} direction="row" p={1}>
<FormControl fullWidth>
<LabelStyle component={'label'} htmlFor="shops">