Skip to content

Commit a6db0d6

Browse files
wang-yikaiYikai
andauthored
fix: add tabIndex support (react-component#779)
Co-authored-by: Yikai <[email protected]>
1 parent d0f9d1d commit a6db0d6

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function RangeSelector<DateType extends object = any>(
111111
required,
112112
'aria-required': ariaRequired,
113113
autoFocus,
114+
tabIndex,
114115

115116
...restProps
116117
} = props;
@@ -241,10 +242,17 @@ function RangeSelector<DateType extends object = any>(
241242
ref={inputStartRef}
242243
{...getInputProps(0)}
243244
autoFocus={startAutoFocus}
245+
tabIndex={tabIndex}
244246
date-range="start"
245247
/>
246248
<div className={`${prefixCls}-range-separator`}>{separator}</div>
247-
<Input ref={inputEndRef} {...getInputProps(1)} autoFocus={endAutoFocus} date-range="end" />
249+
<Input
250+
ref={inputEndRef}
251+
{...getInputProps(1)}
252+
autoFocus={endAutoFocus}
253+
tabIndex={tabIndex}
254+
date-range="end"
255+
/>
248256
<div className={`${prefixCls}-active-bar`} style={activeBarStyle} />
249257
<Icon type="suffix" icon={suffixIcon} />
250258
{showClear && <ClearIcon icon={clearIcon} onClear={onClear} />}

src/PickerInput/Selector/SingleSelector/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import classNames from 'classnames';
22
import * as React from 'react';
33
import type { InternalMode, PickerRef, SelectorProps } from '../../../interface';
44
import { isSame } from '../../../utils/dateUtil';
5-
import PickerContext from '../../context';
65
import type { PickerProps } from '../../SinglePicker';
7-
import useInputProps from '../hooks/useInputProps';
8-
import useRootProps from '../hooks/useRootProps';
6+
import PickerContext from '../../context';
97
import Icon, { ClearIcon } from '../Icon';
108
import Input, { type InputRef } from '../Input';
9+
import useInputProps from '../hooks/useInputProps';
10+
import useRootProps from '../hooks/useRootProps';
1111
import MultipleDates from './MultipleDates';
1212

1313
export interface SingleSelectorProps<DateType extends object = any>
@@ -99,6 +99,7 @@ function SingleSelector<DateType extends object = any>(
9999
required,
100100
'aria-required': ariaRequired,
101101
autoFocus,
102+
tabIndex,
102103

103104
removeIcon,
104105

@@ -178,6 +179,7 @@ function SingleSelector<DateType extends object = any>(
178179
ref={inputRef as any}
179180
readOnly
180181
autoFocus={autoFocus}
182+
tabIndex={tabIndex}
181183
/>
182184
<Icon type="suffix" icon={suffixIcon} />
183185
{showClear && <ClearIcon icon={clearIcon} onClear={onClear} />}
@@ -187,6 +189,7 @@ function SingleSelector<DateType extends object = any>(
187189
ref={inputRef}
188190
{...getInputProps()}
189191
autoFocus={autoFocus}
192+
tabIndex={tabIndex}
190193
suffixIcon={suffixIcon}
191194
clearIcon={showClear && <ClearIcon icon={clearIcon} onClear={onClear} />}
192195
showActiveCls={false}

tests/new-range.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,16 @@ describe('NewPicker.Range', () => {
10951095
);
10961096
});
10971097

1098+
it('pass tabIndex', () => {
1099+
const { container } = render(
1100+
<div>
1101+
<DayRangePicker tabIndex={-1}/>
1102+
</div>,
1103+
);
1104+
1105+
expect(container.querySelector('input').getAttribute('tabIndex')).toBe('-1');
1106+
});
1107+
10981108
describe('7 days', () => {
10991109
const SevenRangePicker = (props: Partial<RangePickerProps<Dayjs>>) => (
11001110
<DayRangePicker

tests/picker.spec.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import type { PanelMode, PickerMode } from '../src/interface';
1313
import enUS from '../src/locale/en_US';
1414
import zhCN from '../src/locale/zh_CN';
1515
import {
16-
clearValue,
17-
closePicker,
18-
confirmOK,
1916
// MomentPicker,
2017
DayPicker,
2118
DayRangePicker,
19+
clearValue,
20+
closePicker,
21+
confirmOK,
2222
findCell,
2323
getDay,
2424
isOpen,
@@ -365,6 +365,16 @@ describe('Picker.Basic', () => {
365365
expect(onBlur).toHaveBeenCalled();
366366
expect(document.querySelector('.rc-picker-focused')).toBeFalsy();
367367
});
368+
369+
it('pass tabIndex', () => {
370+
const { container } = render(
371+
<div>
372+
<DayPicker tabIndex={-1}/>
373+
</div>,
374+
);
375+
376+
expect(container.querySelector('input').getAttribute('tabIndex')).toBe('-1');
377+
});
368378
});
369379

370380
// No need in latest version

tests/range.spec.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import React from 'react';
1111
import type { PickerRef, RangePickerProps } from '../src';
1212
import type { PickerMode } from '../src/interface';
1313
import {
14+
DayRangePicker,
1415
clearValue,
1516
clickButton,
1617
closePicker,
17-
DayRangePicker,
1818
findCell,
1919
getDay,
2020
inputValue,
@@ -537,6 +537,16 @@ describe('Picker.Range', () => {
537537

538538
matchValues(container, '1990-09-13 01:02:03', '1990-09-23 05:06:07');
539539
});
540+
541+
it('pass tabIndex', () => {
542+
const { container } = render(
543+
<div>
544+
<DayRangePicker tabIndex={-1}/>
545+
</div>,
546+
);
547+
548+
expect(container.querySelector('input').getAttribute('tabIndex')).toBe('-1');
549+
});
540550
});
541551

542552
it('mode is array', () => {

0 commit comments

Comments
 (0)