Skip to content

Commit 070e448

Browse files
committed
feat: support prefix prop
1 parent 826726b commit 070e448

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

docs/examples/customize.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Customize extends React.Component<{}, DateRangeState> {
121121
// format="YYYY/MM/DD"
122122
format={['YYYY-MM-DD', 'YYYY/MM/DD']}
123123
allowClear
124+
prefix="Foobar"
124125
clearIcon={<span>X</span>}
125126
suffixIcon={<span>O</span>}
126127
prevIcon={<span>&lt;</span>}

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function RangeSelector<DateType extends object = any>(
5252
const {
5353
id,
5454

55+
prefix,
5556
clearIcon,
5657
suffixIcon,
5758
separator = '~',
@@ -238,6 +239,7 @@ function RangeSelector<DateType extends object = any>(
238239
onMouseDown?.(e);
239240
}}
240241
>
242+
{prefix && <div className={`${prefixCls}-prefix`}>{prefix}</div>}
241243
<Input
242244
ref={inputStartRef}
243245
{...getInputProps(0)}

src/PickerInput/Selector/SingleSelector/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function SingleSelector<DateType extends object = any>(
4343

4444
open,
4545

46+
prefix,
4647
clearIcon,
4748
suffixIcon,
4849
activeHelp,
@@ -224,6 +225,7 @@ function SingleSelector<DateType extends object = any>(
224225
onMouseDown?.(e);
225226
}}
226227
>
228+
{prefix && <div className={`${prefixCls}-prefix`}>{prefix}</div>}
227229
{selectorNode}
228230
</div>
229231
);

src/interface.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ export interface SharedPickerProps<DateType extends object = any>
354354
};
355355

356356
// Icons
357+
prefix?: React.ReactNode;
357358
suffixIcon?: React.ReactNode;
358359
allowClear?:
359360
| boolean

tests/picker.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,16 @@ describe('Picker.Basic', () => {
582582
});
583583
});
584584

585+
it('prefix', () => {
586+
render(
587+
<DayPicker
588+
prefix={<span className="prefix" />}
589+
allowClear
590+
/>,
591+
);
592+
expect(document.querySelector('.prefix')).toBeInTheDocument();
593+
});
594+
585595
it('icon', () => {
586596
expect(errorSpy).not.toHaveBeenCalled();
587597
render(

tests/range.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,16 @@ describe('Picker.Range', () => {
704704
expect(isOpen()).toBeFalsy();
705705
});
706706

707+
it('prefix', () => {
708+
render(
709+
<DayRangePicker
710+
prefix={<span className="prefix" />}
711+
allowClear
712+
/>,
713+
);
714+
expect(document.querySelector('.prefix')).toBeInTheDocument();
715+
});
716+
707717
it('icon', () => {
708718
const { container } = render(
709719
<DayRangePicker

0 commit comments

Comments
 (0)