Skip to content

Commit d06be3a

Browse files
Use ref as target for FileUploader options (fix T1183211) (#864)
1 parent 0db45df commit d06be3a

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/devextreme-react/src/core/__tests__/props-updating.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

packages/devextreme-react/src/core/widget-config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ITemplateMeta } from './template';
22

33
const elementPropNames = ['style', 'id'];
44
const classNamePropName = 'className';
5+
const refPropName = ['dropZone', 'dialogTrigger'];
56

67
function 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 };

0 commit comments

Comments
 (0)