Skip to content

Commit e127035

Browse files
committed
fix(variable-input): initalContent over placeholder
1 parent 82a2da5 commit e127035

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/components/variable-input/variable-input.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const WithInputProps: Story = {
4747

4848
export const WithInitialContent: Story = {
4949
args: {
50+
label: 'Expression',
51+
placeholder: 'Enter the expression',
5052
initialContent: 'Hello {{name}}! How are you?',
5153
options
5254
}

src/components/variable-input/variable-input.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ describe('VariableInput Component', () => {
100100

101101
expect(getByText('No results found')).toBeInTheDocument();
102102
});
103+
104+
it('should prioritize initialContent over placeholder', () => {
105+
const initialContent = 'Initial content';
106+
const { container } = render(<VariableInput options={options} initialContent={initialContent} placeholder="Placeholder" />);
107+
108+
const editor = container.querySelector("[contenteditable='true']");
109+
if (editor) {
110+
expect(editor.innerHTML).toBe(initialContent);
111+
expect(editor.innerHTML).not.toBe('Placeholder');
112+
}
113+
});
103114
});

src/components/variable-input/variable-input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ export function VariableInput({
216216
const editor = editorRef.current;
217217

218218
if (editor) {
219-
if (!isFocused && !text && placeholder) {
219+
if (!isFocused && !text && !initialContent && placeholder) {
220220
editor.innerHTML = placeholderTag;
221221
} else if (isFocused && editor.innerHTML === placeholderTag) {
222222
editor.innerHTML = '';
223223
}
224224
}
225-
}, [isFocused, text, placeholder]);
225+
}, [isFocused, text, placeholder, initialContent]);
226226

227227
React.useEffect(() => {
228228
if (!open) {

0 commit comments

Comments
 (0)