JGuang

Transfer

Transfer · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Transfer

Double column transfer choice box.

When To Use

  • It is a select control essentially which can be used for selecting multiple items.
  • Transfer can display more information for items and take up more space.

Transfer the elements between two columns in an intuitive and efficient way.

One or more elements can be selected from either column, one click on the proper direction button, and the transfer is done. The left column is considered the source and the right column is considered the target. As you can see, these names are reflected in the API.

notice: Transfer is a controlled component, uncontrolled mode is not supported.

Examples

  • Basic · basic
  • One Way · oneWay
  • Search · search
  • Advanced · advanced
  • Custom datasource · custom-item
  • Custom Actions · actions
  • Pagination · large-data
  • Table Transfer · table-transfer
  • Tree Transfer · tree-transfer
  • Status · status
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Transfer

PropertyDescriptionTypeDefaultVersionGlobal Config
actionsA set of operations that are sorted from top to bottom. When an array of strings is provided, default buttons will be used; when an array of ReactNode is provided, custom elements will be usedReactNode[][>, <]6.0.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.06.0.0
dataSourceUsed for setting the source data. The elements that are part of this array will be present the left column. Except the elements whose keys are included in targetKeys propRecordType extends TransferItem = TransferItem[][]×
disabledWhether disabled transferbooleanfalse×
selectionsIconcustom dropdown iconReact.ReactNode5.8.05.14.0
filterOptionA function to determine whether an item should show in search result list, only works when searching, (add direction support since 5.9.0+)(inputValue, option, direction: left | right): boolean-×
footerA function used for rendering the footer(props, { direction }) => ReactNode-direction: 4.17.0×
listStyleA custom CSS style used for rendering the transfer columns. Use styles.section insteadobject | ({direction: left | right}) => object-×
localeThe i18n text including filter, empty text, item unit, etc{ itemUnit: string; itemsUnit: string; searchPlaceholder: string; notFoundContent: ReactNode | ReactNode[]; }{ itemUnit: item, itemsUnit: items, notFoundContent: No data, searchPlaceholder: Search here }×
oneWayDisplay as single direction stylebooleanfalse4.3.0×
operationsA set of operations that are sorted from top to bottom. Use actions instead.string[][>, <]×
operationStyleA custom CSS style used for rendering the operations column. Use styles.actions instead.object-×
paginationUse pagination. Not work in render propsboolean | { pageSize: number, simple: boolean, showSizeChanger?: boolean, showLessItems?: boolean }false4.3.0×
renderThe function to generate the item shown on a column. Based on an record (element of the dataSource array), this function should return a React element which is generated from that record. Also, it can return a plain object with value and label, label is a React element and value is for title(record) => ReactNode-×
selectAllLabelsA set of customized labels for select all checkboxes on the header(ReactNode | (info: { selectedCount: number, totalCount: number }) => ReactNode)[]-×
selectedKeysA set of keys of selected itemsstring[] | number[][]×
showSearchIf included, a search box is shown on each columnboolean | { placeholder:string,defaultValue:string }false×
showSelectAllShow select all checkbox on the headerbooleantrue×
statusSet validation status'error' | 'warning'-4.19.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.06.0.0
targetKeysA set of keys of elements that are listed on the right columnstring[] | number[][]×
titlesA set of titles that are sorted from left to rightReactNode[]-×
onChangeA callback function that is executed when the transfer between columns is complete(targetKeys, direction, moveKeys): void-×
onScrollA callback function which is executed when scroll options list(direction, event): void-×
onSearchA callback function which is executed when search field are changed(direction: left | right, value: string): void-×
onSelectChangeA callback function which is executed when selected items are changed(sourceSelectedKeys, targetSelectedKeys): void-×

Render Props

Transfer accept children to customize render list, using follow props:

PropertyDescriptionTypeVersion
directionList render directionleft | right
disabledDisable list or notboolean
filteredItemsFiltered itemsRecordType[]
selectedKeysSelected itemsstring[] | number[]
onItemSelectSelect item(key: string | number, selected: boolean)
onItemSelectAllSelect a group of items(keys: string[] | number[], selected: boolean)

example

<Transfer {...props}>{(listProps) => <YourComponent {...listProps} />}</Transfer>

Warning

According to the standard of React, the key should always be supplied directly to the elements in the array. In Transfer, the keys should be set on the elements included in dataSource array. By default, key property is used as a unique identifier.

If there's no key in your data, you should use rowKey to specify the key that will be used to uniquely identify each element.

// eg. your primary key is `uid`
return <Transfer rowKey={(record) => record.uid} />;

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with flex layout, transfer container base styles and layout control—
sectionSection element with flex layout, width, height, min height, border, border radius and other single-side transfer container styles—
source.sectionSource section element, only applies to left transfer section container styles6.4.0
target.sectionTarget section element, only applies to right transfer section container styles6.4.0
source.headerSource header element, only applies to left header area styles6.4.0
target.headerTarget header element, only applies to right header area styles6.4.0
source.titleSource title element, only applies to left title text styles6.4.0
target.titleTarget title element, only applies to right title text styles6.4.0
source.bodySource body element, only applies to left list body styles6.4.0
target.bodyTarget body element, only applies to right list body styles6.4.0
source.listSource list element, only applies to left list content styles6.4.0
target.listTarget list element, only applies to right list content styles6.4.0
source.itemSource item element, only applies to left list item styles6.4.0
target.itemTarget item element, only applies to right list item styles6.4.0
source.itemIconSource item icon element, only applies to left icon styles6.4.0
target.itemIconTarget item icon element, only applies to right icon styles6.4.0
source.itemContentSource item content element, only applies to left text content styles6.4.0
target.itemContentTarget item content element, only applies to right text content styles6.4.0
source.footerSource footer element, only applies to left footer area styles6.4.0
target.footerTarget footer element, only applies to right footer area styles6.4.0
headerHeader element with flex layout, alignment, height, padding, color, background color, bottom border, border radius and other header area styles—
titleTitle element with text ellipsis, flex ratio, text alignment, auto left margin and other title text layout and styles—
bodyBody element with list main area container styles and layout control—
listList element with list content styles, layout and scroll control—
itemList item element with relative positioning, padding, border, hover state, selected state, disabled state and other list item interaction styles—
itemIconList item icon element with checkbox and other icon styles and interaction states—
itemContentList item content element with text ellipsis, padding and other list item text content display styles—
footerFooter element with bottom operation area styles and layout—
actionsActions element with transfer button group styles, layout and interaction states—

Semantic description source: vendor/components/transfer/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
listWidthnumber | stringWidth of list
listWidthLGnumber | stringWidth of large list
listHeightnumber | stringHeight of list
itemHeightnumber | stringHeight of list item
itemPaddingBlocknumber | stringVertical padding of list item
headerHeightnumber | stringHeight of header

Declaration source: vendor/components/transfer/style/index.ts

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import { operationUnit, resetComponent, resetIcon, textEllipsis } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

export interface ComponentToken {
  /**
   * @desc 列表宽度
   * @descEN Width of list
   */
  listWidth: number | string;
  /**
   * @desc 大号列表宽度
   * @descEN Width of large list
   */
  listWidthLG: number | string;
  /**
   * @desc 列表高度
   * @descEN Height of list
   */
  listHeight: number | string;
  /**
   * @desc 列表项高度
   * @descEN Height of list item
   */
  itemHeight: number | string;
  /**
   * @desc 列表项纵向内边距
   * @descEN Vertical padding of list item
   */
  itemPaddingBlock: number | string;
  /**
   * @desc 顶部高度
   * @descEN Height of header
   */
  headerHeight: number | string;
}

interface TransferToken extends FullToken<'Transfer'> {
  transferHeaderVerticalPadding: number;
}

FAQ

How to support fetch and present data from a remote server in Transfer column.

In order to keep the page number synchronized, you can disable columns you checked without removing the option: https://codesandbox.io/s/objective-wing-6iqbx

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/transfer/Actions.tsx
  • vendor/components/transfer/ListBody.tsx
  • vendor/components/transfer/ListItem.tsx
  • vendor/components/transfer/Section.tsx
  • vendor/components/transfer/index.tsx
  • vendor/components/transfer/interface.ts
  • vendor/components/transfer/search.tsx
  • vendor/components/transfer/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.