Skip to content

Commit 252c2ea

Browse files
authored
fix(Text): only break words if text can wrap (#6432)
Fixes #6427
1 parent 31f2082 commit 252c2ea

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/main/src/components/Text/Text.cy.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Text', () => {
4444
{longText}
4545
</Text>
4646
);
47-
cy.findByTestId('text').invoke('outerHeight').should('equal', 240);
47+
cy.findByTestId('text').invoke('outerHeight').should('equal', 16);
4848
cy.mount(
4949
<Text data-testid="text" style={{ width: '300px' }} maxLines={1}>
5050
{longText}

packages/main/src/components/Text/Text.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const meta = {
88
children: { control: 'text' }
99
},
1010
args: {
11+
wrapping: true,
1112
children: `If "renderWhitespace" is set to true, there will be thirteen white spaces after this sentence. Lorem ipsum dolor st amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat`
1213
}
1314
} satisfies Meta<typeof Text>;

packages/main/src/components/Text/index.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ export interface TextPropTypes extends CommonProps {
2121
renderWhitespace?: boolean;
2222
/**
2323
* Defines whether the text wraps when there is not enough space.
24+
*
25+
* @detault true
2426
*/
2527
wrapping?: boolean;
2628
/**
2729
* Limits the number of lines for wrapping texts.
30+
*
31+
* __Note:__ This prop only takes effect if the `wrapping` prop is set to `true`.
2832
*/
2933
maxLines?: number;
3034
/**
@@ -64,11 +68,13 @@ const Text = forwardRef<HTMLSpanElement, TextPropTypes>((props, ref) => {
6468
useStylesheet(styleData, Text.displayName);
6569
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
6670

71+
const applyMaxLines = typeof maxLines === 'number' && maxLines > 1;
72+
6773
const classNameString = clsx(
6874
classNames.text,
69-
wrapping === false && classNames.noWrap,
75+
(wrapping === false || (typeof maxLines === 'number' && maxLines <= 1)) && classNames.noWrap,
7076
renderWhitespace && classNames.renderWhitespace,
71-
typeof maxLines === 'number' && classNames.maxLines,
77+
applyMaxLines && classNames.maxLines,
7278
hyphenated && classNames.hyphenated,
7379
className
7480
);
@@ -89,7 +95,12 @@ const Text = forwardRef<HTMLSpanElement, TextPropTypes>((props, ref) => {
8995
return (
9096
<span
9197
ref={ref}
92-
style={{ '--_ui5wcr_maxLines': typeof maxLines === 'number' ? maxLines : undefined, ...style } as CSSProperties}
98+
style={
99+
{
100+
'--_ui5wcr_maxLines': applyMaxLines ? maxLines : undefined,
101+
...style
102+
} as CSSProperties
103+
}
93104
className={classNameString}
94105
{...rest}
95106
>

0 commit comments

Comments
 (0)