import React, { useState, useRef, useEffect } from 'react'; import Icon from '../Icon/index'; import { ISearchInputProps } from '../../type/LargeScreenElement'; import { Input } from 'antd'; import { useRecoilState } from 'recoil'; import { searchValue } from '../../store/page'; import './style.scss'; const SearchInput: React.FC = (props) => { const { change } = props; const [closeShow, setCloseShow] = useState(false); const [inputValue, setInputValue] = useRecoilState(searchValue); //input的value const _changeSearch = (value: string, type: string) => { if (!value) { setCloseShow(false); } else { setCloseShow(true); } setInputValue(value); change?.(value, type); }; return (
} onChange={(e) => _changeSearch(e.target.value, 'change')} onBlur={(e) => { _changeSearch(e.target.value, 'blur'); }} onPressEnter={(e) => { e.preventDefault(); e.stopPropagation(); _changeSearch(e.target.value, 'blur'); }} /> { change?.('', 'change'); setInputValue(''); setCloseShow(false); }} name="icon-delete-filling" style={{ cursor: 'pointer', visibility: closeShow ? 'visible' : 'hidden', color: 'var(--color-font)', marginLeft: 4 }} />
); }; export default SearchInput;