From: afc163 Date: Mon, 20 Feb 2017 08:31:54 +0000 (+0800) Subject: Fix controlled open X-Git-Tag: 2.2.2~2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=71c3a19635d989f1ed99119bf230856d9faeef21;p=github%2Ffretlink%2Ftime-picker.git Fix controlled open --- diff --git a/examples/open.html b/examples/open.html new file mode 100644 index 0000000..e69de29 diff --git a/examples/open.js b/examples/open.js new file mode 100644 index 0000000..5a0d1ed --- /dev/null +++ b/examples/open.js @@ -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 ( +
+ + +
+ ); + }, +}); + +ReactDom.render( + , + document.getElementById('__react-content') +); diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 4d7d4d6..e9d6d15 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -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 }); } } },