Skip to content

Commit 2aa3911

Browse files
committed
Fix layout hug issue
1 parent f5ecde3 commit 2aa3911

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Element.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ export class Element {
4242
if (this.css['width']?.endsWith('px') && this.node.parent) {
4343
if (
4444
this.node.parent.type === 'SECTION' ||
45-
this.node.parent.type === 'PAGE'
45+
this.node.parent.type === 'PAGE' ||
46+
// inline case
47+
(this.node.parent as any).layoutSizingHorizontal == 'HUG'
4648
)
4749
delete this.css['width']
4850
else if (
4951
'width' in this.node.parent &&
5052
this.node.width === this.node.parent.width
51-
)
53+
) {
5254
this.css['width'] = '100%'
55+
}
5356
}
5457
// Image has not padding
5558
return this.css

src/__tests__/Element.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function createNode(
1212
fills,
1313
parent,
1414
layoutPositioning = 'AUTO',
15+
layoutSizingHorizontal,
1516
...props
1617
}: {
1718
[_: string]: any
@@ -26,6 +27,7 @@ function createNode(
2627
type,
2728
getCSSAsync: async () => props,
2829
exportAsync: async () => '<svg>\n<path/>\n</svg>',
30+
layoutSizingHorizontal,
2931
textStyleId,
3032
parent,
3133
characters,
@@ -676,4 +678,18 @@ describe('Element', () => {
676678
)
677679
})
678680
})
681+
682+
describe('Render', () => {
683+
it('should remove width when parent is HUG', async () => {
684+
const element = createElement('FRAME', {
685+
layoutSizingHorizontal: 'HUG',
686+
children: [
687+
createNode('INSTANCE', {
688+
width: '1920px',
689+
}),
690+
],
691+
})
692+
expect(await element.render()).toEqual('<Box>\n <Box />\n</Box>')
693+
})
694+
})
679695
})

0 commit comments

Comments
 (0)