@@ -66,6 +66,11 @@ export interface DatePickerProps extends React.Props<DatePickerType> {
6666 */
6767 onPaste ?: ( newValue : string ) => void ;
6868
69+ /**
70+ * callback for clicking the calendar icon.
71+ */
72+ onExpand ?: ( expanded : boolean ) => void ;
73+
6974 /** Class to append to top level element */
7075 className ?: string ;
7176
@@ -76,7 +81,7 @@ export interface DatePickerState {
7681 value : string ;
7782 initialValue ?: MethodDate ;
7883
79- visible ?: boolean ;
84+ expanded ?: boolean ;
8085}
8186
8287/**
@@ -118,7 +123,7 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
118123 const newState = this . getInitialState ( props , '' ) ;
119124 this . state = {
120125 ...newState ,
121- visible : false ,
126+ expanded : false ,
122127 } ;
123128
124129 this . paste = false ;
@@ -333,14 +338,18 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
333338 }
334339 }
335340
336- onIconClick = ( ) => {
337- const nextVisible = ! this . state . visible ;
341+ onExpand = ( ) => {
342+ const nextExpanded = ! this . state . expanded ;
338343
339- this . setState ( { visible : nextVisible } ) ;
344+ this . setState ( { expanded : nextExpanded } ) ;
345+
346+ if ( typeof this . props . onExpand === 'function' ) {
347+ this . props . onExpand ( nextExpanded ) ;
348+ }
340349 }
341350
342351 onSelect = ( newValue : Date ) => {
343- this . setState ( { visible : false } ) ;
352+ this . setState ( { expanded : false } ) ;
344353 this . props . onChange ( newValue . toJSON ( ) ) ;
345354 }
346355
@@ -349,22 +358,22 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
349358 }
350359
351360 onOuterMouseEvent = ( e : MouseEvent ) => {
352- if ( this . state . visible && ! this . _containerRef . contains ( e . target as HTMLElement ) ) {
353- this . setState ( { visible : false } ) ;
361+ if ( this . state . expanded && ! this . _containerRef . contains ( e . target as HTMLElement ) ) {
362+ this . setState ( { expanded : false } ) ;
354363 }
355364 }
356365
357366 onKeydown = ( e : KeyboardEvent ) => {
358- if ( this . state . visible && e . keyCode === keyCode . escape ) {
367+ if ( this . state . expanded && e . keyCode === keyCode . escape ) {
359368 e . preventDefault ( ) ;
360369 e . stopPropagation ( ) ;
361- this . setState ( { visible : false } ) ;
370+ this . setState ( { expanded : false } ) ;
362371 }
363372 }
364373
365374 onBlur = ( e : React . FocusEvent < any > ) => {
366375 if ( e . relatedTarget && ! this . _containerRef . contains ( e . relatedTarget as HTMLElement ) ) {
367- this . setState ( { visible : false } ) ;
376+ this . setState ( { expanded : false } ) ;
368377 }
369378 }
370379
@@ -418,14 +427,14 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
418427 < ActionTriggerButton
419428 icon = 'calendar'
420429 className = { css ( 'date-picker-calendar-icon' ) }
421- onClick = { this . onIconClick }
430+ onClick = { this . onExpand }
422431 disabled = { this . props . disabled }
423432 attr = { this . props . attr . inputIcon }
424433 aria-haspopup = { true }
425- aria-expanded = { this . state . visible }
434+ aria-expanded = { this . state . expanded }
426435 />
427436 </ Attr . div >
428- { this . state . visible &&
437+ { this . state . expanded &&
429438 < Attr . div
430439 className = { css ( 'date-picker-dropdown' , {
431440 'above' : this . props . showAbove
0 commit comments