File tree Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -289,6 +289,13 @@ class SemanticDatepicker extends React.Component {
289
289
} ) ;
290
290
} ;
291
291
292
+ handleKeyDown = evt => {
293
+ // If the Enter key was pressed...
294
+ if ( evt . keyCode === 13 ) {
295
+ this . handleBlur ( ) ;
296
+ }
297
+ } ;
298
+
292
299
onDateSelected = ( ...args ) => {
293
300
if ( this . isRangeInput ) {
294
301
this . handleRangeInput ( ...args ) ;
@@ -321,6 +328,7 @@ class SemanticDatepicker extends React.Component {
321
328
onChange = { this . handleChange }
322
329
onClear = { this . resetState }
323
330
onClick = { this . showCalendar }
331
+ onKeyDown = { this . handleKeyDown }
324
332
value = { typedValue || selectedDateFormatted }
325
333
/>
326
334
{ isVisible && (
Original file line number Diff line number Diff line change @@ -62,23 +62,15 @@ export const parseFormatString = formatString =>
62
62
formatString . replace ( / [ D , Y ] / gi, a => a . toLowerCase ( ) ) ;
63
63
64
64
export const parseOnBlur = ( typedValue , formatString , isRangeInput ) => {
65
+ const parsedFormatString = parseFormatString ( formatString ) ;
66
+
65
67
if ( isRangeInput ) {
66
68
const rangeValues = typedValue . split ( ' - ' ) ;
67
69
68
70
return rangeValues
69
- . map ( value =>
70
- dateFnsV2 . parse (
71
- value ,
72
- parseFormatString ( formatString , true ) ,
73
- new Date ( )
74
- )
75
- )
71
+ . map ( value => dateFnsV2 . parse ( value , parsedFormatString , new Date ( ) ) )
76
72
. sort ( ( a , b ) => ( a > b ? 1 : - 1 ) ) ;
77
73
}
78
74
79
- return dateFnsV2 . parse (
80
- typedValue ,
81
- parseFormatString ( formatString ) ,
82
- new Date ( )
83
- ) ;
75
+ return dateFnsV2 . parse ( typedValue , parsedFormatString , new Date ( ) ) ;
84
76
} ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { storiesOf } from '@storybook/react' ;
3
+ import parse from 'date-fns/parse' ;
3
4
import { Form } from 'semantic-ui-react' ;
4
5
import 'semantic-ui-css/semantic.min.css' ;
5
6
import SemanticDatepicker from '../src' ;
@@ -91,6 +92,8 @@ storiesOf('Examples', module)
91
92
onDateChange = { console . log }
92
93
format = "DD/MM/YYYY"
93
94
locale = { localePtBr }
95
+ selected = { parse ( '2018-10-01' ) }
96
+ keepOpenOnSelect
94
97
/>
95
98
</ Content >
96
99
) )
You can’t perform that action at this time.
0 commit comments