import React, { useMemo ,useEffect} from 'react'; import Wrap from '../wrap/Wrap'; import Icon from 'src/components/Icon/index'; import { InputNumber, Dropdown, Menu } from 'antd'; import { returnClass } from '../unit'; import '../g.scss'; let isSelect = false; function LabelNumberInputSelect(props: ILabelNumberInputSelect) { const { options, change, value, placeholder = '', min, max, paddingSize, wrapStyle = { padding: '6px 20px 6px 20px' }, title, size = 'normal', padding } = props; const changeSelect = (value: string | number, type: string) => { change?.(value, type); }; useEffect(() => { window.addEventListener('mousedown', (e:any) => { if (e?.target?.className === "zl-ant-dropdown-menu-title-content" || e?.target?.className === "ant-dropdown-menu-title-content" || e?.target?.className === "zl-ls-ant-dropdown-menu-title-content") { isSelect = true; } }) }, []); const menu = ( { changeSelect(key, 'select'); isSelect = false; }} /> ); const Redio = useMemo(() => { return ( {title ? (
{title}
) : ( <> )}
{ changeSelect(value, 'change'); }} onPressEnter={(e) => { e.preventDefault(); e.stopPropagation(); if (e?.target?.value !== '' && !isNaN(e.target.value)) { let value = e.target.value < min ? min : e.target.value; let newValue = value > max ? max : value; changeSelect(newValue, 'blur'); } else { changeSelect(value, 'blur'); } }} onBlur={(e) => { if(isSelect) {return} if (e?.target?.value !== '' && !isNaN(e.target.value)) { let value = e.target.value < min ? min : e.target.value; let newValue = value > max ? max : value; changeSelect(newValue, 'blur'); } else { changeSelect(value, 'blur'); } }} />
); }, [value, options]); return Redio; } export default LabelNumberInputSelect; export interface ILabelNumberInputSelect { label?: string; options?: string[] | number[]; change?: Function; size?: string; value?: string | number; placeholder?: string; min?: number; max?: number; wrapStyle?: React.CSSProperties; paddingSize?: string; title?: string; padding?: number }