From d907505b9f219f4ef2885166846251c7e0c65de9 Mon Sep 17 00:00:00 2001 From: Aleksandr Denisenko Date: Fri, 17 Nov 2017 11:55:18 +0200 Subject: make header input readonly by an optional prop --- src/Header.jsx | 8 +++++++- src/Panel.jsx | 5 ++++- src/TimePicker.jsx | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Header.jsx b/src/Header.jsx index 1520d25..1ba5909 100644 --- a/src/Header.jsx +++ b/src/Header.jsx @@ -10,6 +10,7 @@ class Header extends Component { placeholder: PropTypes.string, clearText: PropTypes.string, value: PropTypes.object, + readOnlyInput: PropTypes.bool, hourOptions: PropTypes.array, minuteOptions: PropTypes.array, secondOptions: PropTypes.array, @@ -26,6 +27,10 @@ class Header extends Component { onKeyDown: PropTypes.func, }; + static defaultProps = { + readOnlyInput: 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, readOnlyInput } = 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={!!readOnlyInput} /> ); } diff --git a/src/Panel.jsx b/src/Panel.jsx index a1b7c77..c23241d 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -27,6 +27,7 @@ class Panel extends Component { value: PropTypes.object, placeholder: PropTypes.string, format: PropTypes.string, + readOnlyInput: 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, + readOnlyInput: 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, readOnlyInput, } = this.props; const { value, currentSelectPanel, @@ -137,6 +139,7 @@ class Panel extends Component { allowEmpty={allowEmpty} focusOnOpen={focusOnOpen} onKeyDown={onKeyDown} + readOnlyInput={readOnlyInput} /> Date: Thu, 1 Feb 2018 14:20:05 +0800 Subject: Rename readOnlyInput to inputReadOnly --- examples/12hours.js | 1 + src/Header.jsx | 8 ++++---- src/Panel.jsx | 8 ++++---- src/TimePicker.jsx | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/12hours.js b/examples/12hours.js index 72d6950..6281210 100644 --- a/examples/12hours.js +++ b/examples/12hours.js @@ -25,6 +25,7 @@ ReactDom.render( onChange={onChange} format={format} use12Hours + inputReadOnly />, document.getElementById('__react-content') ); diff --git a/src/Header.jsx b/src/Header.jsx index 1ba5909..21d557e 100644 --- a/src/Header.jsx +++ b/src/Header.jsx @@ -10,7 +10,7 @@ class Header extends Component { placeholder: PropTypes.string, clearText: PropTypes.string, value: PropTypes.object, - readOnlyInput: PropTypes.bool, + inputReadOnly: PropTypes.bool, hourOptions: PropTypes.array, minuteOptions: PropTypes.array, secondOptions: PropTypes.array, @@ -28,7 +28,7 @@ class Header extends Component { }; static defaultProps = { - readOnlyInput: false, + inputReadOnly: false, } constructor(props) { @@ -171,7 +171,7 @@ class Header extends Component { } getInput() { - const { prefixCls, placeholder, readOnlyInput } = this.props; + const { prefixCls, placeholder, inputReadOnly } = this.props; const { invalid, str } = this.state; const invalidClass = invalid ? `${prefixCls}-input-invalid` : ''; return ( @@ -182,7 +182,7 @@ class Header extends Component { value={str} placeholder={placeholder} onChange={this.onInputChange} - readOnly={!!readOnlyInput} + readOnly={!!inputReadOnly} /> ); } diff --git a/src/Panel.jsx b/src/Panel.jsx index c23241d..1adb19a 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -27,7 +27,7 @@ class Panel extends Component { value: PropTypes.object, placeholder: PropTypes.string, format: PropTypes.string, - readOnlyInput: PropTypes.bool, + inputReadOnly: PropTypes.bool, disabledHours: PropTypes.func, disabledMinutes: PropTypes.func, disabledSeconds: PropTypes.func, @@ -59,7 +59,7 @@ class Panel extends Component { use12Hours: false, addon: noop, onKeyDown: noop, - readOnlyInput: false, + inputReadOnly: false, }; constructor(props) { @@ -98,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, readOnlyInput, + focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly, } = this.props; const { value, currentSelectPanel, @@ -139,7 +139,7 @@ class Panel extends Component { allowEmpty={allowEmpty} focusOnOpen={focusOnOpen} onKeyDown={onKeyDown} - readOnlyInput={readOnlyInput} + inputReadOnly={inputReadOnly} />