Skip to content

Commit 8f5c384

Browse files
authored
feat: support prefix prop (#884)
1 parent 826726b commit 8f5c384

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export type SharedHTMLAttrs = Omit<
302302
| 'max'
303303
| 'onKeyDown'
304304
| 'size'
305+
| 'prefix'
305306
>;
306307

307308
export type PickerFocusEventHandler = (e: React.FocusEvent<HTMLElement>, info: BaseInfo) => void;
@@ -354,6 +355,7 @@ export interface SharedPickerProps<DateType extends object = any>
354355
};
355356

356357
// Icons
358+
prefix?: React.ReactNode;
357359
suffixIcon?: React.ReactNode;
358360
allowClear?:
359361
| boolean
@@ -468,6 +470,7 @@ export type OnOpenChange = (open: boolean, config?: OpenConfig) => void;
468470
export interface SelectorProps<DateType = any> extends SharedHTMLAttrs {
469471
picker: PickerMode;
470472

473+
prefix?: React.ReactNode;
471474
clearIcon?: React.ReactNode;
472475
suffixIcon?: React.ReactNode;
473476
className?: string;

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)