@@ -14,10 +14,12 @@ import {
1414
1515export default class Time extends React . Component {
1616 static propTypes = {
17+ closeDialog : PropTypes . func ,
1718 format : PropTypes . string ,
1819 includeTimes : PropTypes . array ,
1920 intervals : PropTypes . number ,
2021 selected : PropTypes . instanceOf ( Date ) ,
22+ openToDate : PropTypes . instanceOf ( Date ) ,
2123 onChange : PropTypes . func ,
2224 todayButton : PropTypes . node ,
2325 minTime : PropTypes . instanceOf ( Date ) ,
@@ -80,20 +82,28 @@ export default class Time extends React.Component {
8082 this . props . onChange ( time ) ;
8183 } ;
8284
83- liClasses = ( time , currH , currM ) => {
84- let classes = [ "react-datepicker__time-list-item" ] ;
85-
86- if ( currH === getHours ( time ) && currM === getMinutes ( time ) ) {
87- classes . push ( "react-datepicker__time-list-item--selected" ) ;
88- }
89- if (
85+ isDisabledTime = time => {
86+ return (
9087 ( ( this . props . minTime || this . props . maxTime ) &&
9188 isTimeInDisabledRange ( time , this . props ) ) ||
9289 ( this . props . excludeTimes &&
9390 isTimeDisabled ( time , this . props . excludeTimes ) ) ||
9491 ( this . props . includeTimes &&
9592 ! isTimeDisabled ( time , this . props . includeTimes ) )
93+ ) ;
94+ } ;
95+
96+ liClasses = ( time , currH , currM ) => {
97+ let classes = [ "react-datepicker__time-list-item" ] ;
98+
99+ if (
100+ this . props . selected &&
101+ currH === getHours ( time ) &&
102+ currM === getMinutes ( time )
96103 ) {
104+ classes . push ( "react-datepicker__time-list-item--selected" ) ;
105+ }
106+ if ( this . isDisabledTime ( time ) ) {
97107 classes . push ( "react-datepicker__time-list-item--disabled" ) ;
98108 }
99109 if (
@@ -110,7 +120,9 @@ export default class Time extends React.Component {
110120 let times = [ ] ;
111121 const format = this . props . format ? this . props . format : "p" ;
112122 const intervals = this . props . intervals ;
113- const activeTime = this . props . selected ? this . props . selected : newDate ( ) ;
123+ const activeTime =
124+ this . props . selected || this . props . openToDate || newDate ( ) ;
125+
114126 const currH = getHours ( activeTime ) ;
115127 const currM = getMinutes ( activeTime ) ;
116128 let base = getStartOfDay ( newDate ( ) ) ;
@@ -139,22 +151,59 @@ export default class Time extends React.Component {
139151 return times . map ( ( time , i ) => (
140152 < li
141153 key = { i }
142- onClick = { this . handleClick . bind ( this , time ) }
143154 className = { this . liClasses ( time , currH , currM ) }
144155 ref = { li => {
145- if (
146- ( currH === getHours ( time ) && currM === getMinutes ( time ) ) ||
147- ( currH === getHours ( time ) && ! this . centerLi )
148- ) {
156+ if ( currH === getHours ( time ) && currM >= getMinutes ( time ) ) {
149157 this . centerLi = li ;
150158 }
151159 } }
152160 >
153- { formatDate ( time , format , this . props . locale ) }
161+ < button
162+ { ...( this . isDisabledTime ( time ) ? { disabled : "disabled" } : "" ) }
163+ onClick = { this . handleClick . bind ( this , time ) }
164+ >
165+ { formatDate ( time , format , this . props . locale ) }
166+ </ button >
154167 </ li >
155168 ) ) ;
156169 } ;
157170
171+ onKeyDown = e => {
172+ switch ( e . key ) {
173+ case "Up" :
174+ case "ArrowUp" :
175+ this . centerLi = this . centerLi . previousSibling ;
176+ this . centerLi . firstChild . focus ( ) ;
177+ break ;
178+ case "Down" :
179+ case "ArrowDown" :
180+ this . centerLi = this . centerLi . nextSibling ;
181+ this . centerLi . firstChild . focus ( ) ;
182+ break ;
183+ case "Esc" :
184+ case "Escape" :
185+ this . props . closeDialog ( ) ;
186+ break ;
187+ case "Enter" :
188+ case " " :
189+ return ;
190+ case "Home" :
191+ this . centerLi = this . centerLi . parentNode . firstChild ;
192+ this . centerLi . firstChild . focus ( ) ;
193+ break ;
194+ case "End" :
195+ this . centerLi = this . centerLi . parentNode . lastChild ;
196+ this . centerLi . firstChild . focus ( ) ;
197+ break ;
198+ case "Tab" :
199+ return ;
200+ default :
201+ return ;
202+ }
203+
204+ e . preventDefault ( ) ;
205+ } ;
206+
158207 render ( ) {
159208 const { height } = this . state ;
160209
@@ -179,6 +228,7 @@ export default class Time extends React.Component {
179228 < div className = "react-datepicker__time" >
180229 < div className = "react-datepicker__time-box" >
181230 < ul
231+ onKeyDown = { this . onKeyDown }
182232 className = "react-datepicker__time-list"
183233 ref = { list => {
184234 this . list = list ;
0 commit comments