]> git.immae.eu Git - github/fretlink/time-picker.git/commitdiff
Fix controlled open
authorafc163 <afc163@gmail.com>
Mon, 20 Feb 2017 08:31:54 +0000 (16:31 +0800)
committerafc163 <afc163@gmail.com>
Mon, 20 Feb 2017 08:31:54 +0000 (16:31 +0800)
examples/open.html [new file with mode: 0644]
examples/open.js [new file with mode: 0644]
src/TimePicker.jsx

diff --git a/examples/open.html b/examples/open.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/examples/open.js b/examples/open.js
new file mode 100644 (file)
index 0000000..5a0d1ed
--- /dev/null
@@ -0,0 +1,36 @@
+/* eslint no-console:0 */
+
+import 'rc-time-picker/assets/index.less';
+
+import React from 'react';
+import ReactDom from 'react-dom';
+import TimePicker from 'rc-time-picker';
+
+const App = React.createClass({
+  getInitialState() {
+    return {
+      open: false,
+    };
+  },
+  toggleOpen() {
+    this.setState({
+      open: !this.state.open,
+    });
+  },
+  setOpen({ open }) {
+    this.setState({ open });
+  },
+  render() {
+    return (
+      <div>
+        <button onClick={this.toggleOpen}>Toggle open</button>
+        <TimePicker open={this.state.open} onOpen={this.setOpen} onClose={this.setOpen} />
+      </div>
+    );
+  },
+});
+
+ReactDom.render(
+  <App />,
+  document.getElementById('__react-content')
+);
index 4d7d4d6c7416c2953711abd6a8b054273de45b7a..e9d6d15330a11fa26d6d8ca17bba0892648fae66 100644 (file)
@@ -169,19 +169,16 @@ const Picker = React.createClass({
     );
   },
 
-  setOpen(open, callback) {
+  setOpen(open) {
     const { onOpen, onClose } = this.props;
     if (this.state.open !== open) {
-      this.setState({
-        open,
-      }, callback);
-      const event = {
-        open,
-      };
+      if (!('open' in this.props)) {
+        this.setState({ open });
+      }
       if (open) {
-        onOpen(event);
+        onOpen({ open });
       } else {
-        onClose(event);
+        onClose({ open });
       }
     }
   },