]> git.immae.eu Git - github/fretlink/time-picker.git/commitdiff
Merge branch 'abyr-readonly_header_input'
authorWei Zhu <yesmeck@gmail.com>
Thu, 1 Feb 2018 06:20:33 +0000 (14:20 +0800)
committerWei Zhu <yesmeck@gmail.com>
Thu, 1 Feb 2018 06:20:33 +0000 (14:20 +0800)
examples/12hours.js
src/Header.jsx
src/Panel.jsx
src/TimePicker.jsx

index 72d6950027d997da0fabf0870889e4057585106a..6281210960ea0d24a44944f8c097837b53671e0f 100644 (file)
@@ -25,6 +25,7 @@ ReactDom.render(
     onChange={onChange}
     format={format}
     use12Hours
+    inputReadOnly
   />,
   document.getElementById('__react-content')
 );
index 1520d25e3008b371efc66bebfe620d2cf5df4034..21d557edb2c02591589fcaa4234a053728df7a7f 100644 (file)
@@ -10,6 +10,7 @@ class Header extends Component {
     placeholder: PropTypes.string,
     clearText: PropTypes.string,
     value: PropTypes.object,
+    inputReadOnly: PropTypes.bool,
     hourOptions: PropTypes.array,
     minuteOptions: PropTypes.array,
     secondOptions: PropTypes.array,
@@ -26,6 +27,10 @@ class Header extends Component {
     onKeyDown: PropTypes.func,
   };
 
+  static defaultProps = {
+    inputReadOnly: false,
+  }
+
   constructor(props) {
     super(props);
     const { value, format } = props;
@@ -166,7 +171,7 @@ class Header extends Component {
   }
 
   getInput() {
-    const { prefixCls, placeholder } = this.props;
+    const { prefixCls, placeholder, inputReadOnly } = this.props;
     const { invalid, str } = this.state;
     const invalidClass = invalid ? `${prefixCls}-input-invalid` : '';
     return (
@@ -177,6 +182,7 @@ class Header extends Component {
         value={str}
         placeholder={placeholder}
         onChange={this.onInputChange}
+        readOnly={!!inputReadOnly}
       />
     );
   }
index a1b7c77a9cdd1ae19f28b892e2bc979141dc23f1..1adb19a27c32ac122f4425e414b25a39917fc781 100644 (file)
@@ -27,6 +27,7 @@ class Panel extends Component {
     value: PropTypes.object,
     placeholder: PropTypes.string,
     format: PropTypes.string,
+    inputReadOnly: PropTypes.bool,
     disabledHours: PropTypes.func,
     disabledMinutes: PropTypes.func,
     disabledSeconds: PropTypes.func,
@@ -58,6 +59,7 @@ class Panel extends Component {
     use12Hours: false,
     addon: noop,
     onKeyDown: noop,
+    inputReadOnly: false,
   };
 
   constructor(props) {
@@ -96,7 +98,7 @@ class Panel extends Component {
       prefixCls, className, placeholder, disabledHours, disabledMinutes,
       disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
       format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
-      focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
+      focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly,
     } = this.props;
     const {
       value, currentSelectPanel,
@@ -137,6 +139,7 @@ class Panel extends Component {
           allowEmpty={allowEmpty}
           focusOnOpen={focusOnOpen}
           onKeyDown={onKeyDown}
+          inputReadOnly={inputReadOnly}
         />
         <Combobox
           prefixCls={prefixCls}
index e3c5a79fd6e232f675151318000b4c174110c633..7659bc721d6630efe74339ecd211171202daad72 100644 (file)
@@ -18,6 +18,7 @@ export default class Picker extends Component {
     clearText: PropTypes.string,
     value: PropTypes.object,
     defaultOpenValue: PropTypes.object,
+    inputReadOnly: PropTypes.bool,
     disabled: PropTypes.bool,
     allowEmpty: PropTypes.bool,
     defaultValue: PropTypes.object,
@@ -60,6 +61,7 @@ export default class Picker extends Component {
     clearText: 'clear',
     prefixCls: 'rc-time-picker',
     defaultOpen: false,
+    inputReadOnly: false,
     style: {},
     className: '',
     popupClassName: '',
@@ -167,7 +169,7 @@ export default class Picker extends Component {
   getPanelElement() {
     const {
       prefixCls, placeholder, disabledHours,
-      disabledMinutes, disabledSeconds, hideDisabledOptions,
+      disabledMinutes, disabledSeconds, hideDisabledOptions, inputReadOnly,
       allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
       addon, use12Hours, focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
     } = this.props;
@@ -177,6 +179,7 @@ export default class Picker extends Component {
         prefixCls={`${prefixCls}-panel`}
         ref={this.savePanelRef}
         value={this.state.value}
+        inputReadOnly={inputReadOnly}
         onChange={this.onPanelChange}
         onClear={this.onPanelClear}
         defaultOpenValue={defaultOpenValue}