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 () => {
153153 // multiple
154154 format = "YYYY-MM-DD"
155155 showTime
156+ // autoFocus
156157 defaultValue = { [
157158 dayjs ( ) ,
158159 // dayjs('2000-01-01'),
@@ -196,6 +197,7 @@ export default () => {
196197 } }
197198 changeOnBlur = { false }
198199 showNow
200+ autoFocus
199201 panelRender = { ( ori ) => < > 2333{ ori } </ > }
200202 placeholder = { [ 'Start' , 'End' ] }
201203 suffixIcon = "🧶"
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ function RangeSelector<DateType extends object = any>(
108108 // Input
109109 required,
110110 'aria-required' : ariaRequired ,
111+ autoFocus,
111112
112113 ...restProps
113114 } = props ;
@@ -206,6 +207,10 @@ function RangeSelector<DateType extends object = any>(
206207 // ======================== Clear =========================
207208 const showClear = clearIcon && ( ( value [ 0 ] && ! disabled [ 0 ] ) || ( value [ 1 ] && ! disabled [ 1 ] ) ) ;
208209
210+ // ======================= Disabled =======================
211+ const startAutoFocus = autoFocus && ! disabled [ 0 ] ;
212+ const endAutoFocus = autoFocus && ! startAutoFocus && ! disabled [ 1 ] ;
213+
209214 // ======================== Render ========================
210215 return (
211216 < ResizeObserver onResize = { syncActiveOffset } >
@@ -237,9 +242,14 @@ function RangeSelector<DateType extends object = any>(
237242 onMouseDown ?.( e ) ;
238243 } }
239244 >
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+ />
241251 < 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" />
243253 < div className = { `${ prefixCls } -active-bar` } style = { activeBarStyle } />
244254 < Icon type = "suffix" icon = { suffixIcon } />
245255 { showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
Original file line number Diff line number Diff line change 11import classNames from 'classnames' ;
22import * as React from 'react' ;
3- import { isSame } from '../../../utils/dateUtil' ;
43import type { InternalMode , SelectorProps , SelectorRef } from '../../../interface' ;
4+ import { isSame } from '../../../utils/dateUtil' ;
55import PickerContext from '../../context' ;
66import type { PickerProps } from '../../SinglePicker' ;
77import useInputProps from '../hooks/useInputProps' ;
@@ -96,6 +96,7 @@ function SingleSelector<DateType extends object = any>(
9696 // Input
9797 required,
9898 'aria-required' : ariaRequired ,
99+ autoFocus,
99100
100101 ...restProps
101102 } = props ;
@@ -170,6 +171,7 @@ function SingleSelector<DateType extends object = any>(
170171 value = { value . map ( getText ) . join ( ',' ) }
171172 ref = { inputRef as any }
172173 readOnly
174+ autoFocus = { autoFocus }
173175 />
174176 < Icon type = "suffix" icon = { suffixIcon } />
175177 { showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
@@ -178,6 +180,7 @@ function SingleSelector<DateType extends object = any>(
178180 < Input
179181 ref = { inputRef }
180182 { ...getInputProps ( ) }
183+ autoFocus = { autoFocus }
181184 suffixIcon = { suffixIcon }
182185 clearIcon = { showClear && < ClearIcon icon = { clearIcon } onClear = { onClear } /> }
183186 showActiveCls = { false }
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import 'dayjs/locale/ar';
55import { spyElementPrototype } from 'rc-util/lib/test/domHook' ;
66import { resetWarned } from 'rc-util/lib/warning' ;
77import React from 'react' ;
8- import zh_CN from '../src/locale/zh_CN' ;
98import type { RangePickerProps } from '../src' ;
9+ import zh_CN from '../src/locale/zh_CN' ;
1010import {
1111 closePicker ,
1212 DayRangePicker ,
@@ -1196,4 +1196,9 @@ describe('NewPicker.Range', () => {
11961196
11971197 expect ( onChange ) . toHaveBeenCalledWith ( expect . anything ( ) , [ '1990-09-03' , '1990-09-03' ] ) ;
11981198 } ) ;
1199+
1200+ it ( 'autoFocus' , ( ) => {
1201+ const { container } = render ( < DayRangePicker disabled = { [ true , false ] } autoFocus /> ) ;
1202+ expect ( document . activeElement ) . toBe ( container . querySelectorAll ( 'input' ) [ 1 ] ) ;
1203+ } ) ;
11991204} ) ;
Original file line number Diff line number Diff line change @@ -1328,4 +1328,9 @@ describe('Picker.Basic', () => {
13281328
13291329 expect ( document . querySelectorAll ( '.rc-picker-time-panel-column' ) ) . toHaveLength ( 2 ) ;
13301330 } ) ;
1331+
1332+ it ( 'autoFocus' , ( ) => {
1333+ const { container } = render ( < DayPicker autoFocus /> ) ;
1334+ expect ( document . activeElement ) . toBe ( container . querySelector ( 'input' ) ) ;
1335+ } ) ;
13311336} ) ;
You can’t perform that action at this time.
0 commit comments