style: fix calendar style inside Form.Item (#30442)

* style: fix calendar style inside Form.Item

* fix: Calendar set null/undefined throws error

close #30392
This commit is contained in:
afc163 2021-05-08 16:59:03 +08:00 committed by GitHub
parent 0b0849b107
commit 8a599a099f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -31,7 +31,7 @@ function YearSelect<DateType>(props: SharedProps<DateType>) {
divRef,
} = props;
const year = generateConfig.getYear(value);
const year = generateConfig.getYear(value || generateConfig.getNow());
let start = year - YearSelectOffset;
let end = start + YearSelectTotal;
@ -92,7 +92,7 @@ function MonthSelect<DateType>(props: SharedProps<DateType>) {
onChange,
divRef,
} = props;
const month = generateConfig.getMonth(value);
const month = generateConfig.getMonth(value || generateConfig.getNow());
let start = 0;
let end = 11;

View File

@ -27,6 +27,18 @@ describe('Calendar', () => {
findSelectItem(wrapper).at(index).simulate('click');
}
// https://github.com/ant-design/ant-design/issues/30392
it('should be able to set undefined or null', () => {
expect(() => {
const wrapper = mount(<Calendar />);
wrapper.setProps({ value: null });
}).not.toThrow();
expect(() => {
const wrapper = mount(<Calendar />);
wrapper.setProps({ value: undefined });
}).not.toThrow();
});
it('Calendar should be selectable', () => {
const onSelect = jest.fn();
const onChange = jest.fn();

View File

@ -61,7 +61,9 @@
width: 100%;
}
// Don't impact select inside input group
// Don't impact select inside input group and calendar header select
.@{ant-prefix}-picker-calendar-year-select,
.@{ant-prefix}-picker-calendar-month-select,
.@{ant-prefix}-input-group .@{ant-prefix}-select,
.@{ant-prefix}-input-group .@{ant-prefix}-cascader-picker {
width: auto;