mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
fix: table locale not work (#21772)
* fix: Table locale not work * add test case
This commit is contained in:
parent
99e6fb9981
commit
60f77cef23
@ -117,7 +117,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
ConfigContext,
|
||||
);
|
||||
const mergedSize = customizeSize || size;
|
||||
const tableLocale = locale || contextLocale.Table;
|
||||
const tableLocale = { ...contextLocale.Table, ...locale } as TableLocale;
|
||||
const rawData: RecordType[] = dataSource || EMPTY_LIST;
|
||||
|
||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||
@ -241,6 +241,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
|
||||
const [transformFilterColumns, filterStates, getFilters] = useFilter<RecordType>({
|
||||
prefixCls,
|
||||
locale: tableLocale,
|
||||
dropdownPrefixCls,
|
||||
columns: columns || [],
|
||||
onFilterChange,
|
||||
@ -308,6 +309,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
getRecordByKey,
|
||||
expandType,
|
||||
childrenColumnName,
|
||||
locale: tableLocale,
|
||||
});
|
||||
|
||||
const internalRowClassName = (record: RecordType, index: number, indent: number) => {
|
||||
|
@ -1171,4 +1171,31 @@ describe('Table.filter', () => {
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('locale should work', () => {
|
||||
const wrapper = mount(
|
||||
createTable({
|
||||
locale: { filterConfirm: 'Bamboo' },
|
||||
columns: [
|
||||
{
|
||||
...column,
|
||||
filterDropdownVisible: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-table-filter-dropdown-link')
|
||||
.first()
|
||||
.text(),
|
||||
).toEqual('Bamboo');
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-table-filter-dropdown-link')
|
||||
.last()
|
||||
.text(),
|
||||
).toEqual('Reset');
|
||||
});
|
||||
});
|
||||
|
@ -11,8 +11,6 @@ import {
|
||||
} from '../../interface';
|
||||
import { getColumnPos, renderColumnTitle, getColumnKey } from '../../util';
|
||||
import FilterDropdown from './FilterDropdown';
|
||||
import { ConfigContext } from '../../../config-provider';
|
||||
import defaultLocale from '../../../locale/en_US';
|
||||
|
||||
export interface FilterState<RecordType> {
|
||||
column: ColumnType<RecordType>;
|
||||
@ -161,6 +159,7 @@ interface FilterConfig<RecordType> {
|
||||
prefixCls: string;
|
||||
dropdownPrefixCls?: string;
|
||||
columns: ColumnsType<RecordType>;
|
||||
locale: TableLocale;
|
||||
onFilterChange: (
|
||||
filters: Record<string, Key[] | null>,
|
||||
filterStates: FilterState<RecordType>[],
|
||||
@ -174,14 +173,12 @@ function useFilter<RecordType>({
|
||||
columns,
|
||||
onFilterChange,
|
||||
getPopupContainer,
|
||||
locale: tableLocale,
|
||||
}: FilterConfig<RecordType>): [
|
||||
TransformColumns<RecordType>,
|
||||
FilterState<RecordType>[],
|
||||
() => Record<string, Key[] | null>,
|
||||
] {
|
||||
const { locale = defaultLocale } = React.useContext(ConfigContext);
|
||||
const tableLocale = (locale.Table || {}) as TableLocale;
|
||||
|
||||
const [filterStates, setFilterStates] = React.useState<FilterState<RecordType>[]>(
|
||||
collectFilterStates(columns, true),
|
||||
);
|
||||
|
@ -16,8 +16,6 @@ import {
|
||||
TransformColumns,
|
||||
ExpandType,
|
||||
} from '../interface';
|
||||
import { ConfigContext } from '../../config-provider';
|
||||
import defaultLocale from '../../locale/en_US';
|
||||
|
||||
const EMPTY_LIST: any[] = [];
|
||||
|
||||
@ -37,6 +35,7 @@ interface UseSelectionConfig<RecordType> {
|
||||
getRecordByKey: (key: Key) => RecordType;
|
||||
expandType: ExpandType;
|
||||
childrenColumnName: string;
|
||||
locale: TableLocale;
|
||||
}
|
||||
|
||||
type INTERNAL_SELECTION_ITEM = SelectionItem | typeof SELECTION_ALL | typeof SELECTION_INVERT;
|
||||
@ -78,8 +77,6 @@ export default function useSelection<RecordType>(
|
||||
fixed,
|
||||
} = rowSelection || {};
|
||||
|
||||
const { locale = defaultLocale } = React.useContext(ConfigContext);
|
||||
const tableLocale = (locale.Table || {}) as TableLocale;
|
||||
const {
|
||||
prefixCls,
|
||||
data,
|
||||
@ -88,6 +85,7 @@ export default function useSelection<RecordType>(
|
||||
getRowKey,
|
||||
expandType,
|
||||
childrenColumnName,
|
||||
locale: tableLocale,
|
||||
} = config;
|
||||
|
||||
const [innerSelectedKeys, setInnerSelectedKeys] = React.useState<Key[]>();
|
||||
|
Loading…
Reference in New Issue
Block a user