Skip to content

Commit 2e8091d

Browse files
author
Vadim Demedes
committed
Prevent squashing of text nodes if flexDirection="column" is set on container
1 parent c587b30 commit 2e8091d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/render-node-to-output.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ const renderNodeToOutput = (node, output, {offsetX = 0, offsetY = 0, transformer
3232
//
3333
// Also, this is necessary for libraries like ink-link (https://github.com/sindresorhus/ink-link),
3434
// which need to wrap all children at once, instead of wrapping 3 text nodes separately.
35+
const isFlexDirectionColumn = node.style.flexDirection === 'column';
3536
const isAllTextNodes = node.childNodes.every(childNode => {
3637
return Boolean(childNode.nodeValue) || (childNode.nodeName === 'SPAN' && Boolean(childNode.textContent));
3738
});
3839

39-
if (isAllTextNodes) {
40+
if (!isFlexDirectionColumn && isAllTextNodes) {
4041
let text = '';
4142

4243
for (const childNode of node.childNodes) {

test/flex-direction.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import test from 'ava';
3-
import {Box} from '..';
3+
import {Box, Text} from '..';
44
import renderToString from './helpers/render-to-string';
55

66
test('direction row', t => {
@@ -46,3 +46,14 @@ test('direction column reverse', t => {
4646

4747
t.is(output, '\n\nB\nA');
4848
});
49+
50+
test('don\'t squash text nodes when column direction is applied', t => {
51+
const output = renderToString(
52+
<Box flexDirection="column">
53+
<Text>A</Text>
54+
<Text>B</Text>
55+
</Box>
56+
);
57+
58+
t.is(output, 'A\nB');
59+
});

0 commit comments

Comments
 (0)