From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 27 八月 2023 18:37:36 +0800
Subject: [PATCH] 2023-08-27

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

diff --git a/src/menu/stylecontroller/styleInput/index.jsx b/src/menu/stylecontroller/styleInput/index.jsx
index d7661d0..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 = ''
@@ -105,6 +107,7 @@
   }
 
   changeValue = (e) => {
+    const { clear } = this.props
     const { unit } = this.state
     let val = e.target.value
 
@@ -124,28 +127,34 @@
       value: _val,
     })
 
-    if (this.props.onChange) {
-      if (!_val) {
-        this.props.onChange('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