Skip to content

Commit d8a65e5

Browse files
committed
fix: fix radio group default value after edit
1 parent e5648eb commit d8a65e5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/form-js-editor/src/features/properties-panel/entries/ValueEntry.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get, set } from 'min-dash';
1+
import { get, isNil, set } from 'min-dash';
22

33
import { useService } from '../hooks';
44

@@ -76,7 +76,14 @@ function Value(props) {
7676
return;
7777
}
7878

79+
const { defaultValue } = field;
7980
const values = get(field, ['values']);
81+
const previousValue = get(field, ['values', index, 'value']);
82+
83+
if (!isNil(defaultValue) && defaultValue === previousValue) {
84+
set(field, ['defaultValue'], value);
85+
}
86+
8087
return editField(field, 'values', set(values, [index, 'value'], value));
8188
};
8289

packages/form-js-editor/test/spec/features/properties-panel/PropertiesPanel.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,36 @@ describe('properties panel', function () {
410410
expect(editFieldSpy).to.have.been.calledOnce;
411411
expect(editFieldSpy).to.have.been.calledWith(field, ['defaultValue'], undefined);
412412
});
413+
414+
it('should update defaultValue when editing a value that matches current defaultValue', function () {
415+
// given
416+
const editFieldSpy = spy();
417+
418+
const field = {
419+
type: 'select',
420+
key: 'test',
421+
defaultValue: 'camunda-platform',
422+
values: [
423+
{ label: 'Camunda Platform', value: 'camunda-platform' },
424+
{ label: 'Camunda Cloud', value: 'camunda-cloud' },
425+
],
426+
};
427+
428+
bootstrapPropertiesPanel({
429+
container,
430+
editField: editFieldSpy,
431+
field,
432+
});
433+
434+
// when
435+
const defaultOptionInput = screen.getByDisplayValue('camunda-platform');
436+
437+
fireEvent.input(defaultOptionInput, { target: { value: 'new-platform' } });
438+
439+
// then
440+
expect(editFieldSpy).to.have.been.calledOnce;
441+
expect(field.defaultValue).to.equal('new-platform');
442+
});
413443
});
414444

415445
describe('options', function () {

0 commit comments

Comments
 (0)