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} />