Skip to content

Commit cb1162d

Browse files
authored
Fix: Dynamic styles are not applied in React (T1292179) (#30045)
1 parent f54898d commit cb1162d

File tree

9 files changed

+172
-5
lines changed

9 files changed

+172
-5
lines changed

e2e/wrappers/builders/angular19/src/utils/componentFinder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const COMPONENTS = [
99
name: 'InputsListInForm',
1010
component: import('@external/inputs-list-in-form/angular19/inputs-list-in-form.component').then((m) => m.InputsListInFormComponent),
1111
},
12+
{
13+
path: 'text-box-dynamic-styles',
14+
name: 'TextBoxDynamicStyles',
15+
component: import('@external/text-box-dynamic-styles/angular19/text-box-dynamic-styles.component').then((m) => m.TextBoxDynamicStylesComponent),
16+
},
1217
];
1318

1419
export function findComponentByPath(path: string) {

e2e/wrappers/builders/react19/src/utils/componentFinder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const COMPONENTS = [
88
path: 'inputs-list-in-form',
99
name: 'InputsListInForm',
1010
component: () => import('@examples/inputs-list-in-form/react19/index.jsx')
11-
}
11+
},
12+
{
13+
path: 'text-box-dynamic-styles',
14+
name: 'TextBoxDynamicStyles',
15+
component: () => import('@examples/text-box-dynamic-styles/react19/index.jsx')
16+
}
1217
];
1318

1419
export function getAllComponents() {

e2e/wrappers/builders/vue3/src/utils/componentFinder.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ const COMPONENTS = [
55
component: () => import('@examples/button/vue3/index.vue')
66
},
77
{
8-
path: 'inputs-list-in-form',
9-
name: 'InputsListInForm',
10-
component: () => import('@examples/inputs-list-in-form/vue3/index.vue')
8+
path: 'inputs-list-in-form',
9+
name: 'InputsListInForm',
10+
component: () => import('@examples/inputs-list-in-form/vue3/index.vue')
11+
},
12+
{
13+
path: 'text-box-dynamic-styles',
14+
name: 'TextBoxDynamicStyles',
15+
component: () => import('@examples/text-box-dynamic-styles/vue3/index.vue')
1116
}
1217
];
1318

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { TextBoxDynamicStylesComponent } from './text-box-dynamic-styles.component';
2+
3+
export default {
4+
component: TextBoxDynamicStylesComponent,
5+
path: 'text-box-dynamic-styles'
6+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component } from '@angular/core';
2+
import { DxTextBoxModule } from 'devextreme-angular';
3+
4+
@Component({
5+
selector: 'app-text-box-dynamic-styles',
6+
standalone: true,
7+
imports: [DxTextBoxModule],
8+
template: `
9+
<dx-text-box
10+
[value]="value"
11+
(onValueChanged)="onValueChanged($event)"
12+
[style]="boxStyle">
13+
</dx-text-box>
14+
`
15+
})
16+
export class TextBoxDynamicStylesComponent {
17+
value = '';
18+
boxStyle: { [key: string]: string } = {};
19+
20+
private colors = [
21+
'rgb(255, 99, 132)',
22+
'rgb(54, 162, 235)',
23+
'rgb(255, 206, 86)',
24+
'rgb(75, 192, 192)',
25+
'rgb(153, 102, 255)',
26+
];
27+
private colorIndex = 0;
28+
29+
onValueChanged(e: any): void {
30+
this.value = e.value;
31+
32+
this.boxStyle = {
33+
backgroundColor: this.colors[this.colorIndex],
34+
};
35+
36+
this.colorIndex = (this.colorIndex + 1) % this.colors.length;
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { useState, useCallback } from "react";
2+
import { TextBox as DxTextBox } from "devextreme-react/text-box";
3+
4+
const colors = [
5+
'rgb(255, 99, 132)',
6+
'rgb(54, 162, 235)',
7+
'rgb(255, 206, 86)',
8+
'rgb(75, 192, 192)',
9+
'rgb(153, 102, 255)',
10+
];
11+
let colorIndex = 0;
12+
13+
export default function TextBoxDynamicStyles() {
14+
const [value, setValue] = useState('');
15+
const [enableInlineStyles, setEnableInlineStyles] = useState(false);
16+
17+
const onValueChanged = useCallback((e) => {
18+
setValue(e.value);
19+
setEnableInlineStyles(true);
20+
}, []);
21+
22+
const getStyle = () => {
23+
if (enableInlineStyles) {
24+
const changedStyle = {
25+
backgroundColor: colors[colorIndex],
26+
};
27+
28+
colorIndex = (colorIndex + 1) % colors.length;
29+
return changedStyle;
30+
}
31+
return undefined;
32+
};
33+
return (
34+
<div>
35+
<DxTextBox
36+
value={value}
37+
onValueChanged={onValueChanged}
38+
style={getStyle()}
39+
/>
40+
</div>
41+
);
42+
};
43+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<DxTextBox
3+
:value="value"
4+
@value-changed="onValueChanged"
5+
:style="getStyle()" />
6+
</template>
7+
8+
<script setup>
9+
import { ref } from 'vue';
10+
import DxTextBox from 'devextreme-vue/text-box';
11+
12+
const value = ref('');
13+
const enableInlineStyles = ref(false);
14+
15+
const colors = [
16+
'rgb(255, 99, 132)',
17+
'rgb(54, 162, 235)',
18+
'rgb(255, 206, 86)',
19+
'rgb(75, 192, 192)',
20+
'rgb(153, 102, 255)'
21+
];
22+
let colorIndex = 0;
23+
24+
function onValueChanged(e) {
25+
value.value = e.value;
26+
enableInlineStyles.value = true;
27+
}
28+
29+
function getStyle() {
30+
if (enableInlineStyles.value) {
31+
const changedStyle = {
32+
backgroundColor: colors[colorIndex],
33+
};
34+
35+
colorIndex = (colorIndex + 1) % colors.length;
36+
return changedStyle;
37+
}
38+
return {};
39+
}
40+
</script>

e2e/wrappers/tests/textbox.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Selector } from 'testcafe';
2+
import { testInFramework } from '../test-helpers';
3+
4+
testInFramework('TextBox Dynamic Styles scenarios', 'text-box-dynamic-styles', [
5+
'TextBox should update inline styles',
6+
async (t) => {
7+
const textboxWrapper = Selector('.dx-textbox');
8+
const textboxInput = Selector('.dx-texteditor-input');
9+
await t.expect(textboxWrapper.exists).ok('TextBox Wrapper should exist');
10+
await t.expect(textboxInput.exists).ok('TextBox Input should exist');
11+
await t
12+
.typeText(textboxInput, 'trigger')
13+
.pressKey('enter')
14+
.expect(textboxInput.value)
15+
.eql('trigger')
16+
.expect(textboxWrapper.getStyleProperty('background-color'))
17+
.eql('rgb(255, 99, 132)')
18+
.typeText(textboxInput, ' again')
19+
.pressKey('enter')
20+
.expect(textboxInput.value)
21+
.eql('trigger again')
22+
.expect(textboxWrapper.getStyleProperty('background-color'))
23+
.eql('rgb(54, 162, 235)');
24+
},
25+
]);

packages/devextreme-react/src/core/component-base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
199199
}
200200
});
201201
return elementProps;
202-
}, [element.current]);
202+
}, [element.current, props]);
203203

204204
const scheduleTemplatesUpdate = useCallback(() => {
205205
if (guardsUpdateScheduled.current) {

0 commit comments

Comments
 (0)