File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -260,7 +260,7 @@ function RangePicker<DateType extends object = any>(
260
260
setActiveIndex ,
261
261
nextActiveIndex ,
262
262
activeIndexList ,
263
- ] = useRangeActive ( disabled , allowEmpty ) ;
263
+ ] = useRangeActive ( disabled , allowEmpty , mergedOpen ) ;
264
264
265
265
const onSharedFocus = ( event : React . FocusEvent < HTMLElement > , index ?: number ) => {
266
266
triggerFocus ( true ) ;
@@ -627,6 +627,13 @@ function RangePicker<DateType extends object = any>(
627
627
inherit : true ,
628
628
} ) ;
629
629
630
+ // When click input to switch the field, it will not trigger close.
631
+ // Which means it will lose the part confirm and we need fill back.
632
+ // ref: https://github.com/ant-design/ant-design/issues/49512
633
+ if ( activeIndex !== index && mergedOpen && ! needConfirm && complexPicker ) {
634
+ triggerPartConfirm ( null , true ) ;
635
+ }
636
+
630
637
setActiveIndex ( index ) ;
631
638
632
639
onSharedFocus ( event , index ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export type NextActive<DateType> = (nextValue: RangeValueType<DateType>) => numb
14
14
export default function useRangeActive < DateType > (
15
15
disabled : boolean [ ] ,
16
16
empty : boolean [ ] = [ ] ,
17
+ mergedOpen : boolean = false ,
17
18
) : [
18
19
focused : boolean ,
19
20
triggerFocus : ( focused : boolean ) => void ,
@@ -57,7 +58,8 @@ export default function useRangeActive<DateType>(
57
58
} ;
58
59
59
60
// ============================= Effect =============================
60
- useLockEffect ( focused , ( ) => {
61
+ // Wait in case it's from the click outside to blur
62
+ useLockEffect ( focused || mergedOpen , ( ) => {
61
63
if ( ! focused ) {
62
64
activeListRef . current = [ ] ;
63
65
}
Original file line number Diff line number Diff line change @@ -1933,15 +1933,44 @@ describe('Picker.Range', () => {
1933
1933
value : '2024-06-15' ,
1934
1934
} ,
1935
1935
} ) ;
1936
-
1936
+
1937
1937
fireEvent . keyDown ( container . querySelectorAll ( 'input' ) [ 1 ] , {
1938
1938
key : 'Enter' ,
1939
1939
code : 'Enter' ,
1940
1940
} ) ;
1941
-
1942
1941
} ) ;
1943
-
1942
+
1944
1943
expect ( container . querySelectorAll ( 'input' ) [ 1 ] . value ) . toBe ( '2024-06-15' ) ;
1945
1944
expect ( container . querySelectorAll ( 'input' ) [ 0 ] . value ) . toBe ( '2024-06-13' ) ;
1946
1945
} ) ;
1946
+
1947
+ it ( 'click on the input should trigger success when with !needConfirm' , ( ) => {
1948
+ const onChange = jest . fn ( ) ;
1949
+ const { container } = render (
1950
+ < DayRangePicker showTime needConfirm = { false } onChange = { onChange } /> ,
1951
+ ) ;
1952
+
1953
+ // Select first field
1954
+ openPicker ( container , 0 ) ;
1955
+ selectCell ( 1 , 0 ) ;
1956
+
1957
+ // Select second field
1958
+ openPicker ( container , 1 ) ;
1959
+ selectCell ( 2 , 0 ) ;
1960
+
1961
+ // Click outside to blur
1962
+ fireEvent . mouseDown ( document . body ) ;
1963
+ fireEvent . mouseUp ( document . body ) ;
1964
+ fireEvent . click ( document . body ) ;
1965
+
1966
+ act ( ( ) => {
1967
+ jest . advanceTimersByTime ( 1000 ) ;
1968
+ } ) ;
1969
+
1970
+ expect ( onChange ) . toHaveBeenCalledWith ( expect . anything ( ) , [
1971
+ '1990-09-01 00:00:00' ,
1972
+ '1990-09-02 00:00:00' ,
1973
+ ] ) ;
1974
+ expect ( isOpen ( ) ) . toBeFalsy ( ) ;
1975
+ } ) ;
1947
1976
} ) ;
You can’t perform that action at this time.
0 commit comments