Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DatePicker cannot be cleared by set undefined #1100

Merged
merged 3 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/zarm/src/date-picker-view/DatePickerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const DatePickerView = React.forwardRef<DatePickerViewInstance, DatePickerViewPr
const defaultRenderLabel = useRenderLabel(renderLabel);

React.useEffect(() => {
if (props.value === undefined) return;
if (isEqual(props.value, innerValue)) return;
setInnerValue(props.value);
}, [props.value]);
Expand Down
18 changes: 15 additions & 3 deletions packages/zarm/src/date-picker/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,26 @@ ReactDOM.render(<Demo />, mountNode);

```jsx
import { useState } from 'react';
import { Toast, List, DateSelect } from 'zarm';
import { Toast, List, DateSelect, Button } from 'zarm';

const Demo = () => {
const [value, setValue] = useState(new Date());
return (
<List>
<List.Item title="日期选择">
<List.Item
title="日期选择"
suffix={
<Button
size="xs"
onClick={() => {
setValue(undefined);
}}
>清除</Button>
}
>
<DateSelect
onChange={(value, items) => console.log('DateSelect onChange', value, items)}
value={value}
onChange={(value, items) => {console.log('DateSelect onChange', value, items); setValue(value);}}
dominicleo marked this conversation as resolved.
Show resolved Hide resolved
onConfirm={(value, items) => {
Toast.show(value.toLocaleString());
console.log('DateSelect onConfirm', value, items);
Expand Down
2 changes: 1 addition & 1 deletion packages/zarm/src/date-select/DateSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const DateSelect: React.FC<DateSelectProps> = (props) => {
const bem = createBEM('date-select', { prefixCls });

React.useEffect(() => {
if (props.value === undefined) return;
if (isEqual(value, innerValue)) return;
setInnerValue(value);
}, [value]);
Expand All @@ -68,6 +67,7 @@ const DateSelect: React.FC<DateSelectProps> = (props) => {
});

onConfirm?.(changedValue, changedItems);
onChange?.(changedValue, changedItems);
dominicleo marked this conversation as resolved.
Show resolved Hide resolved
};

const handleCancel = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/zarm/src/date-select/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface BaseDateSelectProps extends Omit<BaseDatePickerProps, 'visible'
placeholder?: string;
hasArrow?: boolean;
displayRender?: (items: PickerColumnItem[]) => React.ReactNode;
onChange?: (value: Date, items: PickerColumnItem[]) => void;
dominicleo marked this conversation as resolved.
Show resolved Hide resolved
}