File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
packages/devextreme-react/src/core Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,27 @@ describe('option update', () => {
102102 expect ( Widget . option . mock . calls [ 0 ] [ 1 ] ?. text ) . toEqual ( '1' ) ;
103103 } ) ;
104104
105+ it ( 'component use ref as target element' , ( ) => {
106+ const ref = React . createRef < HTMLDivElement > ( ) ;
107+ const { rerender } = render (
108+ < div >
109+ < div ref = { ref } />
110+ < TestComponent />
111+ </ div > ,
112+ ) ;
113+
114+ rerender (
115+ < div >
116+ < div ref = { ref } />
117+ < TestComponent dropZone = { ref } dialogTrigger = { ref } />
118+ </ div > ,
119+ ) ;
120+
121+ expect ( Widget . option . mock . calls . length ) . toBe ( 2 ) ;
122+ expect ( Widget . option . mock . calls [ 0 ] [ 1 ] ) . toEqual ( ref . current ) ;
123+ expect ( Widget . option . mock . calls [ 1 ] [ 1 ] ) . toEqual ( ref . current ) ;
124+ } ) ;
125+
105126 it ( 'updates nested collection item' , ( ) => {
106127 const TestContainer = ( props : any ) => {
107128 const { value } = props ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { ITemplateMeta } from './template';
22
33const elementPropNames = [ 'style' , 'id' ] ;
44const classNamePropName = 'className' ;
5+ const refPropName = [ 'dropZone' , 'dialogTrigger' ] ;
56
67function isIgnoredProp ( name : string ) {
78 return name === 'children' || name === classNamePropName || elementPropNames . indexOf ( name ) > - 1 ;
@@ -30,20 +31,26 @@ function separateProps(
3031
3132 Object . keys ( props ) . forEach ( ( key ) => {
3233 const defaultOptionName = defaultsProps ? defaultsProps [ key ] : null ;
34+ const value = props [ key ] ;
3335
3436 if ( isIgnoredProp ( key ) ) { return ; }
3537
3638 if ( defaultOptionName ) {
37- defaults [ defaultOptionName ] = props [ key ] ;
39+ defaults [ defaultOptionName ] = value ;
3840 return ;
3941 }
4042
4143 if ( knownTemplates [ key ] ) {
42- templates [ key ] = props [ key ] ;
44+ templates [ key ] = value ;
4345 return ;
4446 }
4547
46- options [ key ] = props [ key ] ;
48+ if ( refPropName . includes ( key ) ) {
49+ options [ key ] = value && value . current ? value . current : value ;
50+ return ;
51+ }
52+
53+ options [ key ] = value ;
4754 } ) ;
4855
4956 return { options, defaults, templates } ;
You can’t perform that action at this time.
0 commit comments