File tree Expand file tree Collapse file tree 3 files changed +41
-23
lines changed Expand file tree Collapse file tree 3 files changed +41
-23
lines changed Original file line number Diff line number Diff line change 13
13
"lint" : " eslint ." ,
14
14
"lint:fix" : " eslint --fix ." ,
15
15
"pret:fix" : " prettier --write ." ,
16
+ "format" : " npm run pret:fix && npm run lint:fix" ,
16
17
"build" : " npm run lint && npm run clean && rollup -c rollup.config.js --bundleConfigAsCjs" ,
17
18
"pub" : " npm run build && np --no-tests" ,
18
19
"dev" : " next dev -p 8888" ,
Original file line number Diff line number Diff line change @@ -268,6 +268,24 @@ const Datepicker = (props: DatepickerType) => {
268
268
}
269
269
} , [ asSingle , startFrom , value ] ) ;
270
270
271
+ useEffect ( ( ) => {
272
+ const handleEscapeKey = ( event : KeyboardEvent ) => {
273
+ const container = calendarContainerRef . current ;
274
+
275
+ if ( ! container || ! container . classList . contains ( "block" ) || event . key !== "Escape" ) {
276
+ return ;
277
+ }
278
+
279
+ hideDatepicker ( ) ;
280
+ } ;
281
+
282
+ document . addEventListener ( "keydown" , handleEscapeKey ) ;
283
+
284
+ return ( ) => {
285
+ document . removeEventListener ( "keydown" , handleEscapeKey ) ;
286
+ } ;
287
+ } , [ hideDatepicker ] ) ;
288
+
271
289
// Variables
272
290
const safePrimaryColor = useMemo ( ( ) => {
273
291
if ( COLORS . includes ( primaryColor ) ) {
Original file line number Diff line number Diff line change @@ -172,38 +172,37 @@ const Input = () => {
172
172
useEffect ( ( ) => {
173
173
const button = buttonRef ?. current ;
174
174
175
+ if ( ! button ) return ;
176
+
175
177
function focusInput ( e : Event ) {
176
178
e . stopPropagation ( ) ;
177
179
const input = inputRef . current ;
178
180
179
- if ( input ) {
180
- input . focus ( ) ;
181
- if ( inputText ) {
182
- changeInputText ( "" ) ;
183
- if ( dayHover ) {
184
- changeDayHover ( null ) ;
185
- }
186
- if ( period . start && period . end ) {
187
- changeDatepickerValue (
188
- {
189
- startDate : null ,
190
- endDate : null
191
- } ,
192
- input
193
- ) ;
194
- }
195
- }
181
+ if ( ! input ) return ;
182
+
183
+ input . focus ( ) ;
184
+
185
+ if ( ! inputText ) return ;
186
+
187
+ changeInputText ( "" ) ;
188
+ if ( dayHover ) {
189
+ changeDayHover ( null ) ;
190
+ }
191
+ if ( period . start && period . end ) {
192
+ changeDatepickerValue (
193
+ {
194
+ startDate : null ,
195
+ endDate : null
196
+ } ,
197
+ input
198
+ ) ;
196
199
}
197
200
}
198
201
199
- if ( button ) {
200
- button . addEventListener ( "click" , focusInput ) ;
201
- }
202
+ button . addEventListener ( "click" , focusInput ) ;
202
203
203
204
return ( ) => {
204
- if ( button ) {
205
- button . removeEventListener ( "click" , focusInput ) ;
206
- }
205
+ button . removeEventListener ( "click" , focusInput ) ;
207
206
} ;
208
207
} , [
209
208
changeDatepickerValue ,
You can’t perform that action at this time.
0 commit comments