Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the omission exception when children in Typography is a temp… #2169

Merged
merged 1 commit into from
Apr 12, 2024
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
17 changes: 17 additions & 0 deletions packages/semi-ui/typography/__test__/typography.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,21 @@ describe(`Typography`, () => {
})
expect(numeral.find('.price').text()).toEqual('1992.15')
})

it('children is template string', () => {
const { Text } = Typography;
const code = 'code';

const typographyParagraph = mount(
<Text
style={{ marginTop: 6, color: 'var(--semi-color-text-2)' }}
ellipsis={{ showTooltip: { opts: { style: { wordBreak: 'break-word' } } } }}
copyable={{ content: code }}
>
Key: {code}
</Text>
);
expect(typographyParagraph.find('.semi-typography').children().at(0).text()).toEqual('Key: code');
});

});
9 changes: 6 additions & 3 deletions packages/semi-ui/typography/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,14 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS

const extraNode = { expand: this.expandRef.current, copy: this.copyRef && this.copyRef.current };

// Perform type conversion on children to prevent component crash due to non-string type of children
// https://github.com/DouyinFE/semi-design/issues/2167
const realChildren = Array.isArray(children) ? children.join('') : String(children);

const content = getRenderText(
this.wrapperRef.current,
rows,
// Perform type conversion on children to prevent component crash due to non-string type of children
String(children),
realChildren,
extraNode,
ELLIPSIS_STR,
suffix,
Expand All @@ -405,7 +408,7 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
this.setState({
isOverflowed: false,
ellipsisContent: content,
isTruncated: children !== content,
isTruncated: realChildren !== content,
}, resolve);
});

Expand Down
Loading