Skip to content

Commit

Permalink
feat: support prefix prop
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyunhe committed Oct 21, 2024
1 parent 826726b commit 070ef28
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/examples/customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Customize extends React.Component<{}, DateRangeState> {
// format="YYYY/MM/DD"
format={['YYYY-MM-DD', 'YYYY/MM/DD']}
allowClear
prefix="Foobar"
clearIcon={<span>X</span>}
suffixIcon={<span>O</span>}
prevIcon={<span>&lt;</span>}
Expand Down
2 changes: 2 additions & 0 deletions src/PickerInput/Selector/RangeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function RangeSelector<DateType extends object = any>(
const {
id,

prefix,
clearIcon,
suffixIcon,
separator = '~',
Expand Down Expand Up @@ -238,6 +239,7 @@ function RangeSelector<DateType extends object = any>(
onMouseDown?.(e);
}}
>
{prefix && <div className={`${prefixCls}-prefix`}>{prefix}</div>}
<Input
ref={inputStartRef}
{...getInputProps(0)}
Expand Down
2 changes: 2 additions & 0 deletions src/PickerInput/Selector/SingleSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function SingleSelector<DateType extends object = any>(

open,

prefix,
clearIcon,
suffixIcon,
activeHelp,
Expand Down Expand Up @@ -224,6 +225,7 @@ function SingleSelector<DateType extends object = any>(
onMouseDown?.(e);
}}
>
{prefix && <div className={`${prefixCls}-prefix`}>{prefix}</div>}
{selectorNode}
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export type SharedHTMLAttrs = Omit<
| 'max'
| 'onKeyDown'
| 'size'
| 'prefix'
>;

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

// Icons
prefix?: React.ReactNode;
suffixIcon?: React.ReactNode;
allowClear?:
| boolean
Expand Down Expand Up @@ -468,6 +470,7 @@ export type OnOpenChange = (open: boolean, config?: OpenConfig) => void;
export interface SelectorProps<DateType = any> extends SharedHTMLAttrs {
picker: PickerMode;

prefix?: React.ReactNode;
clearIcon?: React.ReactNode;
suffixIcon?: React.ReactNode;
className?: string;
Expand Down
10 changes: 10 additions & 0 deletions tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ describe('Picker.Basic', () => {
});
});

it('prefix', () => {
render(
<DayPicker
prefix={<span className="prefix" />}
allowClear
/>,
);
expect(document.querySelector('.prefix')).toBeInTheDocument();
});

it('icon', () => {
expect(errorSpy).not.toHaveBeenCalled();
render(
Expand Down
10 changes: 10 additions & 0 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,16 @@ describe('Picker.Range', () => {
expect(isOpen()).toBeFalsy();
});

it('prefix', () => {
render(
<DayRangePicker
prefix={<span className="prefix" />}
allowClear
/>,
);
expect(document.querySelector('.prefix')).toBeInTheDocument();
});

it('icon', () => {
const { container } = render(
<DayRangePicker
Expand Down

0 comments on commit 070ef28

Please sign in to comment.