diff --git a/components/date-picker/BasePicker.js b/components/date-picker/BasePicker.js index a9397ff2a..410c9fb07 100644 --- a/components/date-picker/BasePicker.js +++ b/components/date-picker/BasePicker.js @@ -20,10 +20,29 @@ class BasePicker extends Component { isFocus: false, text: '', rText: '', - placeholder: '', + leftPlaceholder: '', + rightPlaceholder: '', format: '' } } + setPlaceholder () { + const {placeholder, localeDatas, type} = this.props + const tempPlaceholder = localeDatas.datePicker.placeholders[type] || localeDatas.datePicker.placeholder + let leftPlaceholder = tempPlaceholder + let rightPlaceholder = tempPlaceholder + + if (placeholder instanceof Array) { + leftPlaceholder = placeholder[0] + rightPlaceholder = placeholder[1] || placeholder[0] + } else if (typeof placeholder === 'string') { + leftPlaceholder = placeholder + rightPlaceholder = placeholder + } + this.setState({ + leftPlaceholder, + rightPlaceholder + }) + } static propTypes = { type: PropTypes.oneOf(Object.values(DatePickerType)), value: function (props, propName, componentName) { @@ -93,7 +112,6 @@ class BasePicker extends Component { text: noText ? '' : formatterDate(type, date.startDate || date, format, showTime, localeDatas), rText: noText ? '' : formatterDate(type, date.endDate || date, format, showTime, localeDatas), date, - placeholder: localeDatas.datePicker.placeholders[props.type] || localeDatas.datePicker.placeholder, format }, () => { callback && callback(this.state.date) @@ -108,6 +126,7 @@ class BasePicker extends Component { } this.props.value && this.props.onChange && this.props.onChange(date) }) + this.setPlaceholder() let rect = this.inputRoot.getBoundingClientRect() this.calcPanelPos(rect) } @@ -215,16 +234,18 @@ class BasePicker extends Component { this.timeCancel() } } - _input (text, ref = 'input') { + _input (text, ref = 'input', placeholder = 'Please Select...') { + const {disabled, type, onChange} = this.props + return ( { this[ref] = el }} - placeholder={this.state.placeholder} - className={this.props.disabled ? 'disabled' : ''} - disabled={this.props.disabled} + placeholder={placeholder} + className={disabled ? 'disabled' : ''} + disabled={disabled} onChange={e => { - isVaildDate(new Date(e.target.value)) && this.props.type === 'date' && this.props.onChange(new Date(e.target.value)) + isVaildDate(new Date(e.target.value)) && type === 'date' && onChange(new Date(e.target.value)) this.setState({ text: e.target.value }) @@ -274,9 +295,9 @@ class BasePicker extends Component { ) return (
Date 实例: