Showing
1 changed file
with
23 additions
and
0 deletions
@@ -99,6 +99,29 @@ const FormSelectMain: React.FC<FormSelectProps>= (props)=> { | @@ -99,6 +99,29 @@ const FormSelectMain: React.FC<FormSelectProps>= (props)=> { | ||
99 | } | 99 | } |
100 | }, [JSON.stringify(value), JSON.stringify(options)]); | 100 | }, [JSON.stringify(value), JSON.stringify(options)]); |
101 | 101 | ||
102 | + // 用来监听页面点击关闭选择框 | ||
103 | + useEffect(() => { | ||
104 | + const controlVisible= (e: MouseEvent)=> { | ||
105 | + if(state.modalVisible) return | ||
106 | + let selectBox = document.getElementsByClassName('qx-form-select'); // 这个是自己的区域 | ||
107 | + let flag = false; | ||
108 | + Array.prototype.forEach.call(selectBox, function (element) { | ||
109 | + if(element.contains(e.target)) { | ||
110 | + flag = true; | ||
111 | + } | ||
112 | + }); | ||
113 | + if (!flag) { | ||
114 | + inputSelectRef.current?.closeDropdown(); | ||
115 | + } | ||
116 | + } | ||
117 | + // 监听页面点击关闭操作 | ||
118 | + document.addEventListener('click', controlVisible); | ||
119 | + | ||
120 | + return () => { | ||
121 | + document.removeEventListener('click', controlVisible) | ||
122 | + } | ||
123 | + }, []); | ||
124 | + | ||
102 | 125 | ||
103 | return ( | 126 | return ( |
104 | <div className={cls(prefix, className)}> | 127 | <div className={cls(prefix, className)}> |