2
2
* React Component Base
3
3
*/
4
4
import * as React from 'react' ;
5
+ import * as ReactDOM from 'react-dom' ;
5
6
import { extend , isNullOrUndefined , setValue , getValue , isObject } from '@syncfusion/ej2-base' ;
6
7
/**
7
8
* Interface for processing directives
74
75
public portals :any ;
75
76
protected value : any ;
76
77
protected columns : any ;
78
+ private clsName : boolean ;
77
79
78
80
// Lifecycle methods are changed by React team and so we can deprecate this method and use
79
81
// Reference link:https://reactjs.org/docs/react-component.html#unsafe_componentWillMount
91
93
}
92
94
}
93
95
94
- public componentDidUpdate ( ) : any {
96
+ public componentDidUpdate ( prev : Object ) : any {
95
97
if ( ! this . isshouldComponentUpdateCalled && this . initRenderCalled && ! this . isReactForeceUpdate ) {
96
98
this . isshouldComponentUpdateCalled = true ;
97
- this . refreshProperties ( this . props , true ) ;
99
+ if ( prev !== this . props ) {
100
+ this . refreshProperties ( this . props , true ) ;
101
+ }
98
102
}
99
103
}
100
104
145
149
delete dProps [ propkey ] ;
146
150
} else if ( this . attrKeys . indexOf ( propkey ) !== - 1 ) {
147
151
if ( isClassName ) {
148
- this . element . classList . remove ( this . props [ propkey ] ) ;
149
- this . element . classList . add ( dProps [ propkey ] ) ;
152
+ this . clsName = true ;
153
+ let propsClsName = this . props [ propkey ] . split ( ' ' ) ;
154
+ for ( let i : number = 0 ; i < propsClsName . length ; i ++ ) {
155
+ this . element . classList . remove ( propsClsName [ i ] ) ;
156
+ }
157
+ let dpropsClsName = dProps [ propkey ] . split ( ' ' ) ;
158
+ for ( let j : number = 0 ; j < dpropsClsName . length ; j ++ ) {
159
+ this . element . classList . add ( dpropsClsName [ j ] ) ;
160
+ }
150
161
} else if ( propkey !== 'disabled' ) {
151
162
delete dProps [ propkey ] ;
152
163
}
153
164
}
165
+ else if ( propkey === 'value' && nextProps [ propkey ] === this [ propkey ] ) {
166
+ delete dProps [ propkey ] ;
167
+ }
168
+ else if ( ( propkey === 'valueTemplate' || propkey === 'itemTemplate' ) && nextProps [ propkey ] . toString ( ) === this [ propkey ] . toString ( ) ) {
169
+ delete dProps [ propkey ] ;
170
+ }
154
171
}
155
172
if ( dProps [ 'children' ] ) {
156
173
delete dProps [ 'children' ] ;
218
235
ComponentBase . reactUid ++ ;
219
236
}
220
237
238
+ }
239
+ if ( this . clsName ) {
240
+ let clsList : string [ ] = this . element . classList ;
241
+ let className : any = this . htmlattributes [ 'className' ] ;
242
+ for ( let i : number = 0 ; i < clsList . length ; i ++ ) {
243
+ if ( ( className . indexOf ( clsList [ i ] ) == - 1 ) ) {
244
+ this . htmlattributes [ 'className' ] = this . htmlattributes [ 'className' ] + ' ' + clsList [ i ] ;
245
+ }
246
+ }
247
+ this . clsName = false ;
221
248
}
222
249
return this . htmlattributes ;
223
250
}
303
330
let keys : string [ ] = Object . keys ( newProp ) ;
304
331
if ( keys . length !== 0 ) {
305
332
for ( let key of keys ) {
306
- let oldValue = oldProp [ key ] ;
307
- let newValue = newProp [ key ] ;
333
+ let oldValue : any = oldProp [ key ] ;
334
+ let newValue : any = newProp [ key ] ;
335
+ if ( key === 'items' ) {
336
+ for ( var _j = 0 ; _j < newValue . length ; _j ++ ) {
337
+ if ( this . getModuleName ( ) === 'richtexteditor' && typeof ( newValue [ _j ] ) === 'object' ) {
338
+ return { status : true } ;
339
+ }
340
+ }
341
+ }
308
342
if ( this . getModuleName ( ) === 'grid' && key === 'field' ) {
309
343
curObj [ key ] = newValue ;
310
344
}
311
- if ( ! oldProp . hasOwnProperty ( key ) || ! this . compareValues ( newValue , oldValue ) ) {
345
+ if ( ! oldProp . hasOwnProperty ( key ) || ! this . compareValues ( oldValue , newValue ) ) {
312
346
if ( ! propName ) {
313
347
return { status : false } ;
314
348
}
419
453
}
420
454
421
455
}
456
+
457
+ // tslint:disable:no-any
458
+ public appendReactElement ( element : any , container : HTMLElement ) {
459
+ ReactDOM . render ( ( ReactDOM as any ) . createPortal ( element , container ) , container ) ;
460
+ } ;
461
+
422
462
// tslint:disable:no-any
423
463
public renderReactTemplates ( callback ?: any ) : void {
424
464
this . isReactForeceUpdate = true ;
542
582
}
543
583
}
544
584
/* tslint:enable:no-any */
545
-
585
+
0 commit comments