@@ -14,7 +14,7 @@ import type { TransferKey } from "antd/es/transfer/interface";
1414import { useResizeDetector } from "react-resize-detector" ;
1515import { changeEvent , eventHandlerControl , searchEvent , selectedChangeEvent } from "../controls/eventHandlerControl" ;
1616import styled , { css } from "styled-components" ;
17- import { useContext , useEffect , useRef , useState } from "react" ;
17+ import { useContext , useEffect , useRef , useState , useCallback } from "react" ;
1818import { valueComp , withDefault } from "../generators" ;
1919import type { TransferDirection } from 'antd/es/transfer' ;
2020import React from "react" ;
@@ -64,11 +64,12 @@ const childrenMap = {
6464 oneWay : BoolControl ,
6565 pagination : BoolControl ,
6666 showSearch : BoolControl . DEFAULT_TRUE ,
67+ caseSensitive : BoolControl ,
6768 pageSize : withDefault ( NumberControl , 10 ) ,
6869 items : arrayObjectExposingStateControl ( 'items' , defaultItems as any ) ,
6970 targetKeys : arrayStringExposingStateControl ( 'targetKeys' , [ ] ) ,
70- selectedKeys : valueComp < any > ( [ [ ] , [ ] ] ) ,
71- targerObject : valueComp < any > ( [ ] ) ,
71+ selectedKeys : arrayStringExposingStateControl ( 'selectedKeys' , [ ] ) ,
72+ targetObject : arrayObjectExposingStateControl ( 'targetObject' , [ ] ) ,
7273 searchInfo : valueComp < string [ ] > ( [ '' , '' ] ) ,
7374} ;
7475
@@ -80,7 +81,6 @@ const TransferView = React.memo((props: RecordConstructorToView<typeof childrenM
8081 const conRef = useRef < HTMLDivElement > ( null ) ;
8182 const [ width , setWidth ] = useState ( 0 ) ;
8283 const [ height , setHeight ] = useState ( 0 ) ;
83- const [ selectedKeys , setSelectedKeys ] = useState < string [ ] > ( [ ] ) ;
8484
8585 useEffect ( ( ) => {
8686 if ( height && width ) {
@@ -90,13 +90,16 @@ const TransferView = React.memo((props: RecordConstructorToView<typeof childrenM
9090
9191 const handleChange = ( newTargetKeys : TransferKey [ ] ) => {
9292 props . targetKeys . onChange ( newTargetKeys as string [ ] ) ;
93- props . dispatch ( changeChildAction ( "targerObject" , Array . isArray ( props . items . value ) ? props . items . value . filter ( item => newTargetKeys . includes ( item . key as string ) ) : [ ] , false ) ) ;
93+ const targetObjects = Array . isArray ( props . items . value )
94+ ? props . items . value . filter ( item => newTargetKeys . includes ( item . key as string ) )
95+ : [ ] ;
96+ props . targetObject . onChange ( targetObjects ) ;
9497 props . onEvent ( 'change' )
9598 } ;
9699
97100 const onSelectChange = ( sourceSelectedKeys : TransferKey [ ] , targetSelectedKeys : TransferKey [ ] ) => {
98- setSelectedKeys ( [ ...sourceSelectedKeys , ...targetSelectedKeys ] as string [ ] ) ;
99- props . dispatch ( changeChildAction ( " selectedKeys" , [ sourceSelectedKeys as string [ ] , targetSelectedKeys as string [ ] ] , false ) ) ;
101+ const allSelectedKeys = [ ...sourceSelectedKeys , ...targetSelectedKeys ] as string [ ] ;
102+ props . selectedKeys . onChange ( allSelectedKeys ) ;
100103 props . onEvent ( 'selectedChange' )
101104 } ;
102105
@@ -105,6 +108,13 @@ const TransferView = React.memo((props: RecordConstructorToView<typeof childrenM
105108 props . onEvent ( 'search' )
106109 } ;
107110
111+ const filterOption = useCallback ( ( inputValue : string , item : RecordType ) => {
112+ if ( props . caseSensitive ) {
113+ return item . title ?. includes ( inputValue ) ?? false ;
114+ }
115+ return item . title ?. toLowerCase ( ) . includes ( inputValue . toLowerCase ( ) ) ?? false ;
116+ } , [ props . caseSensitive ] ) ;
117+
108118 const onResize = ( ) => {
109119 const container = conRef . current ;
110120 setWidth ( container ?. clientWidth ?? 0 ) ;
@@ -130,10 +140,11 @@ const TransferView = React.memo((props: RecordConstructorToView<typeof childrenM
130140 dataSource = { props . items . value as any }
131141 titles = { [ props . targetTitle , props . sourceTitle ] }
132142 targetKeys = { props . targetKeys . value }
133- selectedKeys = { selectedKeys }
143+ selectedKeys = { props . selectedKeys . value }
134144 onChange = { handleChange }
135145 onSelectChange = { onSelectChange }
136146 render = { ( item : RecordType ) => item . title }
147+ filterOption = { filterOption }
137148 oneWay = { props . oneWay }
138149 onSearch = { handleSearch }
139150 pagination = { props . pagination ? {
@@ -153,8 +164,8 @@ const TransferCompPropertyView = React.memo((props: {
153164 { props . children . items . propertyView ( {
154165 label : trans ( "transfer.items" ) ,
155166 } ) }
156- { props . children . targetKeys . propertyView ( {
157- label : trans ( "transfer.targetKeys " ) ,
167+ { props . children . selectedKeys . propertyView ( {
168+ label : trans ( "transfer.selectedKeys " ) ,
158169 } ) }
159170 { props . children . sourceTitle . propertyView ( {
160171 label : trans ( "transfer.sourceTitle" ) ,
@@ -165,6 +176,9 @@ const TransferCompPropertyView = React.memo((props: {
165176 { props . children . showSearch . propertyView ( {
166177 label : trans ( "transfer.allowSearch" ) ,
167178 } ) }
179+ { props . children . showSearch . getView ( ) && props . children . caseSensitive . propertyView ( {
180+ label : trans ( "transfer.caseSensitive" ) ,
181+ } ) }
168182 { props . children . oneWay . propertyView ( {
169183 label : trans ( "transfer.oneWay" ) ,
170184 } ) }
@@ -202,7 +216,7 @@ TransferBasicComp = class extends TransferBasicComp {
202216export const transferComp = withExposingConfigs ( TransferBasicComp , [
203217 new NameConfig ( "items" , trans ( "transfer.items" ) ) ,
204218 new NameConfig ( "targetKeys" , trans ( "transfer.targetKeys" ) ) ,
205- new NameConfig ( "targerObject " , trans ( "transfer.targerObject " ) ) ,
219+ new NameConfig ( "targetObject " , trans ( "transfer.targetObject " ) ) ,
206220 new NameConfig ( "selectedKeys" , trans ( "transfer.selectedKeys" ) ) ,
207221 new NameConfig ( "searchInfo" , trans ( "transfer.searchInfo" ) ) ,
208222 NameConfigHidden ,
0 commit comments