Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default React.forwardRef<HTMLTextAreaElement, TextareaCodeEditorProps>((p
/>
),
// eslint-disable-next-line react-hooks/exhaustive-deps
[prefixCls, language, htmlStr],
[prefixCls, language, htmlStr, padding, minHeight],
);

const change = (evn: React.ChangeEvent<HTMLTextAreaElement>) => {
Expand Down
36 changes: 36 additions & 0 deletions core/src/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@ it('TextareaCodeEditor language="html"', async () => {
}
});

it('TextareaCodeEditor keeps preview padding in sync when padding changes', () => {
const props = { language: 'js', value: 'const value = 1;' };
const { rerender } = render(<TextareaCodeEditor {...props} padding={10} />);
const textbox = screen.getByRole('textbox');
// eslint-disable-next-line testing-library/no-node-access
const preview = textbox.nextElementSibling;

for (const padding of [10, 24, 0, undefined]) {
rerender(<TextareaCodeEditor {...props} padding={padding} />);
const expectedPadding = `${padding ?? 10}px`;
const expectedStyle = {
paddingTop: expectedPadding,
paddingRight: expectedPadding,
paddingBottom: expectedPadding,
paddingLeft: expectedPadding,
};
expect(textbox).toHaveStyle(expectedStyle);
expect(preview).toHaveStyle(expectedStyle);
}
});

it('TextareaCodeEditor keeps preview minHeight in sync when minHeight changes', () => {
const props = { language: 'js', value: 'const value = 1;' };
const { rerender } = render(<TextareaCodeEditor {...props} minHeight={16} />);
const textbox = screen.getByRole('textbox');
// eslint-disable-next-line testing-library/no-node-access
const preview = textbox.nextElementSibling;

for (const minHeight of [16, 120, undefined]) {
rerender(<TextareaCodeEditor {...props} minHeight={minHeight} />);
const expectedStyle = { minHeight: `${minHeight ?? 16}px` };
expect(textbox).toHaveStyle(expectedStyle);
expect(preview).toHaveStyle(expectedStyle);
}
});

it('TextareaCodeEditor onChange 1', async () => {
const MyComponent = () => {
const txtRef = useRef<HTMLTextAreaElement>(null);
Expand Down
Loading