File tree Expand file tree Collapse file tree 5 files changed +29
-4
lines changed Expand file tree Collapse file tree 5 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ export default () => {
153
153
// multiple
154
154
format = "YYYY-MM-DD"
155
155
showTime
156
+ // autoFocus
156
157
defaultValue = { [
157
158
dayjs ( ) ,
158
159
// dayjs('2000-01-01'),
@@ -196,6 +197,7 @@ export default () => {
196
197
} }
197
198
changeOnBlur = { false }
198
199
showNow
200
+ autoFocus
199
201
panelRender = { ( ori ) => < > 2333{ ori } </ > }
200
202
placeholder = { [ 'Start' , 'End' ] }
201
203
suffixIcon = "🧶"
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ function RangeSelector<DateType extends object = any>(
108
108
// Input
109
109
required,
110
110
'aria-required' : ariaRequired ,
111
+ autoFocus,
111
112
112
113
...restProps
113
114
} = props ;
@@ -206,6 +207,10 @@ function RangeSelector<DateType extends object = any>(
206
207
// ======================== Clear =========================
207
208
const showClear = clearIcon && ( ( value [ 0 ] && ! disabled [ 0 ] ) || ( value [ 1 ] && ! disabled [ 1 ] ) ) ;
208
209
210
+ // ======================= Disabled =======================
211
+ const startAutoFocus = autoFocus && ! disabled [ 0 ] ;
212
+ const endAutoFocus = autoFocus && ! startAutoFocus && ! disabled [ 1 ] ;
213
+
209
214
// ======================== Render ========================
210
215
return (
211
216
< ResizeObserver onResize = { syncActiveOffset } >
@@ -237,9 +242,14 @@ function RangeSelector<DateType extends object = any>(
237
242
onMouseDown ?.( e ) ;
238
243
} }
239
244
>
240
- < Input ref = { inputStartRef } { ...getInputProps ( 0 ) } date-range = "start" />
245
+ < Input
246
+ ref = { inputStartRef }
247
+ { ...getInputProps ( 0 ) }
248
+ autoFocus = { startAutoFocus }
249
+ date-range = "start"
250
+ />
241
251
< div className = { `${ prefixCls } -range-separator` } > { separator } </ div >
242
- < Input ref = { inputEndRef } { ...getInputProps ( 1 ) } date-range = "end" />
252
+ < Input ref = { inputEndRef } { ...getInputProps ( 1 ) } autoFocus = { endAutoFocus } date-range = "end" />
243
253
< div className = { `${ prefixCls } -active-bar` } style = { activeBarStyle } />
244
254
< Icon type = "suffix" icon = { suffixIcon } />
245
255
{ showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
Original file line number Diff line number Diff line change 1
1
import classNames from 'classnames' ;
2
2
import * as React from 'react' ;
3
- import { isSame } from '../../../utils/dateUtil' ;
4
3
import type { InternalMode , SelectorProps , SelectorRef } from '../../../interface' ;
4
+ import { isSame } from '../../../utils/dateUtil' ;
5
5
import PickerContext from '../../context' ;
6
6
import type { PickerProps } from '../../SinglePicker' ;
7
7
import useInputProps from '../hooks/useInputProps' ;
@@ -96,6 +96,7 @@ function SingleSelector<DateType extends object = any>(
96
96
// Input
97
97
required,
98
98
'aria-required' : ariaRequired ,
99
+ autoFocus,
99
100
100
101
...restProps
101
102
} = props ;
@@ -170,6 +171,7 @@ function SingleSelector<DateType extends object = any>(
170
171
value = { value . map ( getText ) . join ( ',' ) }
171
172
ref = { inputRef as any }
172
173
readOnly
174
+ autoFocus = { autoFocus }
173
175
/>
174
176
< Icon type = "suffix" icon = { suffixIcon } />
175
177
{ showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
@@ -178,6 +180,7 @@ function SingleSelector<DateType extends object = any>(
178
180
< Input
179
181
ref = { inputRef }
180
182
{ ...getInputProps ( ) }
183
+ autoFocus = { autoFocus }
181
184
suffixIcon = { suffixIcon }
182
185
clearIcon = { showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
183
186
showActiveCls = { false }
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import 'dayjs/locale/ar';
5
5
import { spyElementPrototype } from 'rc-util/lib/test/domHook' ;
6
6
import { resetWarned } from 'rc-util/lib/warning' ;
7
7
import React from 'react' ;
8
- import zh_CN from '../src/locale/zh_CN' ;
9
8
import type { RangePickerProps } from '../src' ;
9
+ import zh_CN from '../src/locale/zh_CN' ;
10
10
import {
11
11
closePicker ,
12
12
DayRangePicker ,
@@ -1196,4 +1196,9 @@ describe('NewPicker.Range', () => {
1196
1196
1197
1197
expect ( onChange ) . toHaveBeenCalledWith ( expect . anything ( ) , [ '1990-09-03' , '1990-09-03' ] ) ;
1198
1198
} ) ;
1199
+
1200
+ it ( 'autoFocus' , ( ) => {
1201
+ const { container } = render ( < DayRangePicker disabled = { [ true , false ] } autoFocus /> ) ;
1202
+ expect ( document . activeElement ) . toBe ( container . querySelectorAll ( 'input' ) [ 1 ] ) ;
1203
+ } ) ;
1199
1204
} ) ;
Original file line number Diff line number Diff line change @@ -1328,4 +1328,9 @@ describe('Picker.Basic', () => {
1328
1328
1329
1329
expect ( document . querySelectorAll ( '.rc-picker-time-panel-column' ) ) . toHaveLength ( 2 ) ;
1330
1330
} ) ;
1331
+
1332
+ it ( 'autoFocus' , ( ) => {
1333
+ const { container } = render ( < DayPicker autoFocus /> ) ;
1334
+ expect ( document . activeElement ) . toBe ( container . querySelector ( 'input' ) ) ;
1335
+ } ) ;
1331
1336
} ) ;
You can’t perform that action at this time.
0 commit comments