fix(site-builder): Container 40px drop-zone min-height only when empty
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01d5ba5496
commit
7d77201e5a
2 files changed
+37
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { describe, test, expect, afterEach } from 'vitest';
|
||||
import { renderEditorHarness, EditorHarness } from '../../test-utils/editorHarness';
|
||||
|
||||
// The 40px min-height is an editor-only DROP ZONE for EMPTY containers. A container that has
|
||||
// content must lay out like the published page (no injected min-height).
|
||||
const node = (type: string, props: Record<string, unknown>, nodes: string[] = [], extra: Record<string, unknown> = {}) => ({
|
||||
type: { resolvedName: type }, isCanvas: type === 'Container' || type === 'Text', props, displayName: type, custom: {}, hidden: false, nodes, linkedNodes: {}, ...extra,
|
||||
});
|
||||
let h: EditorHarness | null = null;
|
||||
afterEach(() => { h?.unmount(); h = null; });
|
||||
const mount = (inner: Record<string, any>, withChild: boolean) => {
|
||||
h = renderEditorHarness({
|
||||
initialState: JSON.stringify({
|
||||
ROOT: node('Container', { tag: 'div', style: {} }, ['c1']),
|
||||
c1: node('Container', { tag: 'section', ...inner }, withChild ? ['t1'] : [], { parent: 'ROOT' }),
|
||||
...(withChild ? { t1: node('TextBlock', { text: 'hi', style: {} }, [], { parent: 'c1' }) } : {}),
|
||||
}),
|
||||
});
|
||||
return h.container.querySelector('section') as HTMLElement;
|
||||
};
|
||||
|
||||
describe('Container empty-only drop zone', () => {
|
||||
test('empty container keeps the 40px drop zone', () => {
|
||||
expect(mount({ style: {} }, false).style.minHeight).toBe('40px');
|
||||
});
|
||||
test('non-empty container does NOT get an injected min-height', () => {
|
||||
expect(mount({ style: {} }, true).style.minHeight).toBe('');
|
||||
});
|
||||
test('an explicit style.minHeight always wins', () => {
|
||||
expect(mount({ style: { minHeight: '100px' } }, true).style.minHeight).toBe('100px');
|
||||
expect(mount({ style: { minHeight: '100px' } }, false).style.minHeight).toBe('100px');
|
||||
});
|
||||
});
|
||||
@@ -95,8 +95,11 @@ export const Container: UserComponent<ContainerProps> = ({
|
||||
// follows the current device's Alignment / Vertical alignment.
|
||||
const layout = containerLayout(style, needsBoxedWrapper);
|
||||
|
||||
// 40px min-height = editor-only DROP ZONE, so only an EMPTY container gets it. A container with
|
||||
// content must size like the published page (toHtml adds no min-height).
|
||||
const isEmpty = React.Children.count(children) === 0;
|
||||
const outerStyle: CSSProperties = {
|
||||
minHeight: '40px',
|
||||
...(isEmpty ? { minHeight: '40px' } : {}),
|
||||
...style,
|
||||
...(fullWidth ? { width: '100vw', marginLeft: 'calc(-50vw + 50%)' } : {}),
|
||||
...layout.outer,
|
||||
|
||||
Reference in new issue
Block a user