Skip to content

Commit 6021fab

Browse files
committed
feat: Support aria pass to input
1 parent f1790c6 commit 6021fab

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

src/Picker.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import PickerPanel, {
2222
} from './PickerPanel';
2323
import PickerTrigger from './PickerTrigger';
2424
import { isEqual } from './utils/dateUtil';
25-
import { toArray } from './utils/miscUtil';
25+
import getDataOrAriaProps, { toArray } from './utils/miscUtil';
2626
import PanelContext, { ContextOperationRefProps } from './PanelContext';
2727
import { PickerMode } from './interface';
2828
import {
@@ -31,7 +31,7 @@ import {
3131
addGlobalMouseDownEvent,
3232
} from './utils/uiUtil';
3333

34-
export interface PickerSharedProps<DateType> {
34+
export interface PickerSharedProps<DateType> extends React.AriaAttributes {
3535
dropdownClassName?: string;
3636
dropdownAlign?: AlignType;
3737
popupStyle?: React.CSSProperties;
@@ -65,6 +65,9 @@ export interface PickerSharedProps<DateType> {
6565
// Internal
6666
/** @private Internal usage, do not use in production mode!!! */
6767
inputRef?: React.Ref<HTMLInputElement>;
68+
69+
// WAI-ARIA
70+
role?: string;
6871
}
6972

7073
export interface PickerBaseProps<DateType>
@@ -481,6 +484,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
481484
placeholder={placeholder}
482485
ref={inputRef}
483486
size={getInputSize(picker, formatList[0])}
487+
{...getDataOrAriaProps(props)}
484488
/>
485489
{suffixNode}
486490
{clearNode}

src/RangePicker.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* TODO:
3+
* - Highlight range when hover the ranges value
4+
* - Click ranges value will go to the related panel
5+
*/
6+
17
import * as React from 'react';
28
import classNames from 'classnames';
39
import Picker, {

src/utils/miscUtil.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ export function toArray<T>(val: T | T[]): T[] {
1919

2020
return Array.isArray(val) ? val : [val];
2121
}
22+
23+
export default function getDataOrAriaProps(props: any) {
24+
const retProps: any = {};
25+
26+
Object.keys(props).forEach(key => {
27+
if (
28+
(key.substr(0, 5) === 'data-' ||
29+
key.substr(0, 5) === 'aria-' ||
30+
key === 'role') &&
31+
key.substr(0, 7) !== 'data-__'
32+
) {
33+
retProps[key] = props[key];
34+
}
35+
});
36+
37+
return retProps;
38+
}

tests/__snapshots__/picker.spec.tsx.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ exports[`Basic icon 1`] = `
2525
</span>
2626
</div>
2727
`;
28+
29+
exports[`Basic pass data- & aria- & role 1`] = `
30+
<div
31+
class="rc-picker"
32+
>
33+
<div
34+
class="rc-picker-input"
35+
>
36+
<input
37+
aria-label="3334"
38+
data-test="233"
39+
readonly=""
40+
role="search"
41+
size="12"
42+
value=""
43+
/>
44+
</div>
45+
</div>
46+
`;

tests/picker.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,12 @@ describe('Basic', () => {
494494
isSame(onSelect.mock.calls[0][0], '1990-09-03 00:00:00', 'second'),
495495
).toBeTruthy();
496496
});
497+
498+
it('pass data- & aria- & role', () => {
499+
const wrapper = mount(
500+
<MomentPicker data-test="233" aria-label="3334" role="search" />,
501+
);
502+
503+
expect(wrapper.render()).toMatchSnapshot();
504+
});
497505
});

0 commit comments

Comments
 (0)