Skip to content

Commit 3b9d5d5

Browse files
authored
fix/COMPASS-9798 sync field name to prop (#153)
1 parent eb90fe9 commit 3b9d5d5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/components/field/field-name-content.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export const FieldNameContent = ({ name, isEditable, onChange }: FieldNameProps)
3232
const [value, setValue] = useState(name);
3333
const textInputRef = useRef<HTMLInputElement>(null);
3434

35+
useEffect(() => {
36+
setValue(name);
37+
}, [name]);
38+
3539
const handleSubmit = useCallback(() => {
3640
setIsEditing(false);
3741
onChange?.(value);

src/components/field/field.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ describe('field', () => {
141141
await userEvent.dblClick(fieldName);
142142
expect(screen.queryByDisplayValue('ordersId')).not.toBeUndefined();
143143
});
144+
145+
it('Should sync with prop changes', async () => {
146+
const originalName = 'originalName';
147+
const newName = 'newName';
148+
const { rerender } = render(
149+
<FieldWithEditableInteractions {...DEFAULT_PROPS} editable={true} name={originalName} />,
150+
);
151+
expect(screen.getByText(originalName)).toBeInTheDocument();
152+
await rerender(<FieldWithEditableInteractions {...DEFAULT_PROPS} editable={true} name={newName} />);
153+
expect(screen.getByText(newName)).toBeInTheDocument();
154+
});
144155
});
145156

146157
describe('With specific types', () => {

0 commit comments

Comments
 (0)