mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
parent
e039b10b2f
commit
6c0f67e407
@ -2305,4 +2305,53 @@ describe('Table.filter', () => {
|
|||||||
);
|
);
|
||||||
expect(errorSpy).not.toBeCalled();
|
expect(errorSpy).not.toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can reset if filterResetToDefaultFilteredValue and filter is changing', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
createTable({
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
...column,
|
||||||
|
filters: [
|
||||||
|
{ text: 'Jack', value: 'Jack' },
|
||||||
|
{ text: 'Lucy', value: 'Lucy' },
|
||||||
|
],
|
||||||
|
defaultFilteredValue: ['Jack'],
|
||||||
|
filterResetToDefaultFilteredValue: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(wrapper.find('tbody tr').length).toBe(1);
|
||||||
|
expect(wrapper.find('tbody tr').text()).toBe('Jack');
|
||||||
|
|
||||||
|
// open filter
|
||||||
|
wrapper.find('span.ant-dropdown-trigger').first().simulate('click');
|
||||||
|
expect(
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-link').props().disabled,
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(wrapper.find('li.ant-dropdown-menu-item').at(0).text()).toBe('Jack');
|
||||||
|
expect(wrapper.find('li.ant-dropdown-menu-item').at(1).text()).toBe('Lucy');
|
||||||
|
|
||||||
|
// deselect default
|
||||||
|
wrapper.find('li.ant-dropdown-menu-item').at(0).simulate('click');
|
||||||
|
expect(
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-link').props().disabled,
|
||||||
|
).toBeFalsy();
|
||||||
|
// select other one
|
||||||
|
wrapper.find('li.ant-dropdown-menu-item').at(1).simulate('click');
|
||||||
|
expect(
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-link').props().disabled,
|
||||||
|
).toBeFalsy();
|
||||||
|
// deselect other one
|
||||||
|
wrapper.find('li.ant-dropdown-menu-item').at(1).simulate('click');
|
||||||
|
expect(
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-link').props().disabled,
|
||||||
|
).toBeFalsy();
|
||||||
|
// select default
|
||||||
|
wrapper.find('li.ant-dropdown-menu-item').at(0).simulate('click');
|
||||||
|
expect(
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-btns .ant-btn-link').props().disabled,
|
||||||
|
).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -407,16 +407,22 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getResetDisabled = () => {
|
||||||
|
if (filterResetToDefaultFilteredValue) {
|
||||||
|
return isEqual(
|
||||||
|
(defaultFilteredValue || []).map(key => String(key)),
|
||||||
|
selectedKeys,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedKeys.length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
dropdownContent = (
|
dropdownContent = (
|
||||||
<>
|
<>
|
||||||
{getFilterComponent()}
|
{getFilterComponent()}
|
||||||
<div className={`${prefixCls}-dropdown-btns`}>
|
<div className={`${prefixCls}-dropdown-btns`}>
|
||||||
<Button
|
<Button type="link" size="small" disabled={getResetDisabled()} onClick={() => onReset()}>
|
||||||
type="link"
|
|
||||||
size="small"
|
|
||||||
disabled={selectedKeys.length === 0}
|
|
||||||
onClick={() => onReset()}
|
|
||||||
>
|
|
||||||
{locale.filterReset}
|
{locale.filterReset}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="primary" size="small" onClick={onConfirm}>
|
<Button type="primary" size="small" onClick={onConfirm}>
|
||||||
|
Loading…
Reference in New Issue
Block a user