@@ -14,6 +14,13 @@ import enUs from './locale/en_US';
14
14
import { getTimeConfig , getTodayTime , syncTime } from './util' ;
15
15
import { goStartMonth , goEndMonth , goTime } from './util/toTime' ;
16
16
17
+ const getMomentObjectIfValid = date => {
18
+ if ( moment . isMoment ( date ) && date . isValid ( ) ) {
19
+ return date ;
20
+ }
21
+ return false ;
22
+ } ;
23
+
17
24
const Calendar = {
18
25
props : {
19
26
locale : PropTypes . object . def ( enUs ) ,
@@ -46,6 +53,7 @@ const Calendar = {
46
53
renderSidebar : PropTypes . func . def ( ( ) => null ) ,
47
54
clearIcon : PropTypes . any ,
48
55
focusablePanel : PropTypes . bool . def ( true ) ,
56
+ inputMode : PropTypes . string ,
49
57
} ,
50
58
51
59
mixins : [ BaseMixin , CommonMixin , CalendarMixin ] ,
@@ -54,7 +62,10 @@ const Calendar = {
54
62
const props = this . $props ;
55
63
return {
56
64
sMode : this . mode || 'date' ,
57
- sValue : props . value || props . defaultValue || moment ( ) ,
65
+ sValue :
66
+ getMomentObjectIfValid ( props . value ) ||
67
+ getMomentObjectIfValid ( props . defaultValue ) ||
68
+ moment ( ) ,
58
69
sSelectedValue : props . selectedValue || props . defaultSelectedValue ,
59
70
} ;
60
71
} ,
@@ -63,9 +74,11 @@ const Calendar = {
63
74
this . setState ( { sMode : val } ) ;
64
75
} ,
65
76
value ( val ) {
66
- const sValue = val || this . defaultValue || getNowByCurrentStateValue ( this . sValue ) ;
67
77
this . setState ( {
68
- sValue,
78
+ sValue :
79
+ getMomentObjectIfValid ( val ) ||
80
+ getMomentObjectIfValid ( this . defaultValue ) ||
81
+ getNowByCurrentStateValue ( this . sValue ) ,
69
82
} ) ;
70
83
} ,
71
84
selectedValue ( val ) {
@@ -190,6 +203,25 @@ const Calendar = {
190
203
source : 'todayButton' ,
191
204
} ) ;
192
205
} ,
206
+
207
+ onBlur ( event ) {
208
+ setTimeout ( ( ) => {
209
+ const dateInput = DateInput . getInstance ( ) ;
210
+ const rootInstance = this . rootInstance ;
211
+
212
+ if (
213
+ ! rootInstance ||
214
+ rootInstance . contains ( document . activeElement ) ||
215
+ ( dateInput && dateInput . contains ( document . activeElement ) )
216
+ ) {
217
+ // focused element is still part of Calendar
218
+ return ;
219
+ }
220
+
221
+ this . $emit ( 'blur' , event ) ;
222
+ } , 0 ) ;
223
+ } ,
224
+
193
225
getRootDOMNode ( ) {
194
226
return this . $el ;
195
227
} ,
@@ -217,6 +249,9 @@ const Calendar = {
217
249
sSelectedValue,
218
250
sMode,
219
251
renderFooter,
252
+ inputMode,
253
+ monthCellRender,
254
+ monthCellContentRender,
220
255
$props : props ,
221
256
} = this ;
222
257
const clearIcon = getComponentFromProp ( this , 'clearIcon' ) ;
@@ -267,6 +302,7 @@ const Calendar = {
267
302
onChange = { this . onDateInputChange }
268
303
clearIcon = { clearIcon }
269
304
onSelect = { this . onDateInputSelect }
305
+ inputMode = { inputMode }
270
306
/>
271
307
) : null ;
272
308
const children = [ ] ;
@@ -286,6 +322,8 @@ const Calendar = {
286
322
renderFooter = { renderFooter }
287
323
showTimePicker = { showTimePicker }
288
324
prefixCls = { prefixCls }
325
+ monthCellRender = { monthCellRender }
326
+ monthCellContentRender = { monthCellContentRender }
289
327
/>
290
328
{ timePicker && showTimePicker ? (
291
329
< div class = { `${ prefixCls } -time-picker` } >
0 commit comments