From 0b8381328068394891541b6e3824f9afb2cc9fa1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 04 七月 2023 13:53:33 +0800
Subject: [PATCH] 2023-07-04

---
 src/menu/stylecontroller/styleInput/index.jsx |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/menu/stylecontroller/styleInput/index.jsx b/src/menu/stylecontroller/styleInput/index.jsx
index d3a93a0..52b9c1c 100644
--- a/src/menu/stylecontroller/styleInput/index.jsx
+++ b/src/menu/stylecontroller/styleInput/index.jsx
@@ -21,6 +21,8 @@
     options: null
   }
 
+  timer = null
+
   UNSAFE_componentWillMount () {
     const { defaultValue, value, options } = this.props
     let val = ''
@@ -125,28 +127,34 @@
       value: _val,
     })
 
-    if (this.props.onChange) {
-      if (!_val) {
-        this.props.onChange(clear ? '' : '0px')
-      } else {
-        this.props.onChange(`${_val}${unit}`)
+    clearTimeout(this.timer)
+
+    this.timer = setTimeout(() => {
+      if (this.props.onChange) {
+        if (_val === '') {
+          this.props.onChange(clear ? '' : '0px')
+        } else {
+          this.props.onChange(`${_val}${unit}`)
+        }
       }
-    }
+    }, 100)
   }
 
   changeUnit = (val) => {
     const { value } = this.state
 
-    this.setState({unit: val})
-
-    if (val === 'auto') {
-      this.setState({value: ''})
-      this.props.onChange('auto')
-    } else {
-      if (value && this.props.onChange) {
-        this.props.onChange(`${value}${val}`)
+    this.setState({unit: val}, () => {
+      if (val === 'auto') {
+        this.setState({value: ''})
+        this.props.onChange('auto')
+      } else {
+        if (value && this.props.onChange) {
+          this.props.onChange(`${value}${val}`)
+        } else {
+          this.props.onChange('')
+        }
       }
-    }
+    })
   }
 
   render () {

--
Gitblit v1.8.0