Browse Source

fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT (#23462)

* fix:selections type when use SELECTION_ALL | SELECTION_INVERT

* fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT

* fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT

* Update useSelection.tsx

* Update type.test.tsx

Co-authored-by: 二货机器人 <smith3816@gmail.com>
pull/23508/head
xiaoxintang 5 years ago
committed by GitHub
parent
commit
937beba421
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      components/table/__tests__/type.test.tsx
  2. 9
      components/table/hooks/useSelection.tsx
  3. 3
      components/table/interface.tsx

6
components/table/__tests__/type.test.tsx

@ -24,6 +24,12 @@ describe('Table.typescript', () => {
);
expect(table).toBeTruthy();
});
it('selections', () => {
const table = (
<Table rowSelection={{ selections: [Table.SELECTION_ALL] }} />
);
expect(table).toBeTruthy();
});
});
describe('Table.typescript types', () => {

9
components/table/hooks/useSelection.tsx

@ -21,8 +21,8 @@ import {
const EMPTY_LIST: any[] = [];
// TODO: warning if use ajax!!!
export const SELECTION_ALL = 'SELECT_ALL';
export const SELECTION_INVERT = 'SELECT_INVERT';
export const SELECTION_ALL = 'SELECT_ALL' as const;
export const SELECTION_INVERT = 'SELECT_INVERT' as const;
function getFixedType<RecordType>(column: ColumnsType<RecordType>[number]): FixedType | undefined {
return column && column.fixed;
@ -41,7 +41,10 @@ interface UseSelectionConfig<RecordType> {
getPopupContainer?: GetPopupContainer;
}
type INTERNAL_SELECTION_ITEM = SelectionItem | typeof SELECTION_ALL | typeof SELECTION_INVERT;
export type INTERNAL_SELECTION_ITEM =
| SelectionItem
| typeof SELECTION_ALL
| typeof SELECTION_INVERT;
function flattenData<RecordType>(
data: RecordType[] | undefined,

3
components/table/interface.tsx

@ -6,6 +6,7 @@ import {
} from 'rc-table/lib/interface';
import { CheckboxProps } from '../checkbox';
import { PaginationConfig } from '../pagination';
import { INTERNAL_SELECTION_ITEM } from './hooks/useSelection';
export { GetRowKey, ExpandableConfig };
@ -130,7 +131,7 @@ export interface TableRowSelection<T> {
onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
/** @deprecated This function is meaningless and should use `onChange` instead */
onSelectInvert?: (selectedRowKeys: Key[]) => void;
selections?: SelectionItem[] | boolean;
selections?: INTERNAL_SELECTION_ITEM[] | boolean;
hideDefaultSelections?: boolean;
fixed?: boolean;
columnWidth?: string | number;

Loading…
Cancel
Save