Skip to content

Commit 23e427f

Browse files
authored
feat: id should work on Picker (#54)
* feat: support picker id * rangepicker
1 parent f8da184 commit 23e427f

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/Picker.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface PickerSharedProps<DateType> extends React.AriaAttributes {
4949
defaultOpen?: boolean;
5050
/** Make input readOnly to avoid popup keyboard in mobile */
5151
inputReadOnly?: boolean;
52+
id?: string;
5253

5354
// Value
5455
format?: string | string[];
@@ -127,6 +128,7 @@ interface MergedPickerProps<DateType>
127128
function InnerPicker<DateType>(props: PickerProps<DateType>) {
128129
const {
129130
prefixCls = 'rc-picker',
131+
id,
130132
style,
131133
className,
132134
dropdownClassName,
@@ -463,6 +465,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
463465
>
464466
<div className={`${prefixCls}-input`} ref={inputDivRef}>
465467
<input
468+
id={id}
466469
disabled={disabled}
467470
readOnly={inputReadOnly || !typing}
468471
value={text}

src/RangePicker.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function canValueTrigger<DateType>(
5555
}
5656

5757
export interface RangePickerSharedProps<DateType> {
58+
id?: string;
5859
value?: RangeValue<DateType>;
5960
defaultValue?: RangeValue<DateType>;
6061
defaultPickerValue?: [DateType, DateType];
@@ -136,6 +137,7 @@ interface MergedRangePickerProps<DateType>
136137
function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
137138
const {
138139
prefixCls = 'rc-picker',
140+
id,
139141
style,
140142
className,
141143
popupStyle,
@@ -887,6 +889,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
887889
ref={startInputDivRef}
888890
>
889891
<input
892+
id={id}
890893
disabled={mergedDisabled[0]}
891894
readOnly={inputReadOnly || !startTyping}
892895
value={startText}

tests/picker.spec.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,9 @@ describe('Picker.Basic', () => {
612612
expect(wrapper.find('input').props().value).toEqual(text);
613613
});
614614
});
615+
616+
it('id', () => {
617+
const wrapper = mount(<MomentPicker id="light" />);
618+
expect(wrapper.find('input').props().id).toEqual('light');
619+
});
615620
});

tests/range.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,4 +1036,14 @@ describe('Picker.Range', () => {
10361036
testOrderOnTime(false, '23:00:00', '02:00:00');
10371037
testOrderOnTime(true, '02:00:00', '23:00:00');
10381038
});
1039+
1040+
it('id', () => {
1041+
const wrapper = mount(<MomentRangePicker id="bamboo" />);
1042+
expect(
1043+
wrapper
1044+
.find('input')
1045+
.first()
1046+
.props().id,
1047+
).toEqual('bamboo');
1048+
});
10391049
});

0 commit comments

Comments
 (0)