Skip to content
7 changes: 7 additions & 0 deletions .changeset/single-line-word-break.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feat] Change the single-line Text and Heading truncation default from `break-all` to `break-word`; pass `wordBreak="break-all"` to opt into splitting inside words

@bezabyte
4 changes: 2 additions & 2 deletions apps/storybook/stories/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export const WordBreakVariants: Story = {
<div style={{display: 'flex', gap: '16px', maxWidth: '600px'}}>
<div style={{flex: 1}}>
<Text type="label" display="block">
break-word (default for multi-line):
break-word (default for truncation):
</Text>
<div style={{width: '150px', border: '1px solid #ccc', padding: '8px'}}>
<Text type="body" maxLines={2} wordBreak="break-word">
Expand All @@ -420,7 +420,7 @@ export const WordBreakVariants: Story = {
</div>
<div style={{flex: 1}}>
<Text type="label" display="block">
break-all (default for single-line):
break-all (explicit opt-in):
</Text>
<div style={{width: '150px', border: '1px solid #ccc', padding: '8px'}}>
<Text type="body" maxLines={2} wordBreak="break-all">
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/components/Heading/Heading.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR1 | `level` renders `h1`–`h6`. `accessibilityLevel` adds `aria-level` only when it differs from `level`. | Current source and tests |
| FR2 | The heading carries the `heading` target reflecting `level`, `color`, and any supplied `type` and `weight`. A built-in `type` applies its display scale and default weight; otherwise the level's scale applies. A theme-added `type` keeps the level's scale as its baseline. An explicit `weight` wins over the type and level defaults. | Current source and tests |
| FR3 | `color` defaults to `primary`; a theme-added color keeps the primary baseline until a theme paints it. `hasCapsize` renders `block` and trims to cap height; otherwise `maxLines` above 1 renders the line-clamp box, `maxLines={1}` renders `block`, and otherwise `display` (default `block`) applies. `justify` uses logical values; `start`, the default, sets no alignment, so the element follows its container's. `textWrap` and `hasStrikethrough` apply their text treatments. Without truncation, a token longer than its line wraps, so in ordinary flow the text does not force horizontal scrolling at 320 CSS px (`spec:AST-020` FR1, WCAG 2.2 1.4.10 Reflow). The heading's `overflow-wrap` is `break-word`, which keeps min-content, so tables and auto-sized columns lay out ordinary words unchanged; inside a Core container that wraps its content with `anywhere` (CommandPaletteEmpty, Toast, FieldStatus, Banner), it is `anywhere`, as the container's own text is. A flex child needs `min-width: 0` from its container, and a caller's own container that sets `overflow-wrap: anywhere` does not reach the heading's text. | Current source and tests |
| FR4 | `maxLines={1}` clips one line with an ellipsis; a larger value clamps to that many lines unless `hasCapsize` is set, whose `block` display removes the clamp. With truncation, `wordBreak` defaults to `break-all` for one line and `break-word` otherwise. When the text is measured as truncated and `hasTruncateTooltip` is not `false`, a lazily loaded Tooltip anchored to the heading shows the full text at the given placement (default `above`); no native `title` is added. `hasTruncateTooltip={false}` takes no measurement. A truncation tooltip can be opened from the keyboard (WCAG 2.2 2.1.1). Implementation gap: the tooltip opens on hover and touch only, because the heading is not focusable (Current-state impact). | Current source and tests |
| FR4 | `maxLines={1}` clips one line with an ellipsis; a larger value clamps to that many lines unless `hasCapsize` is set, whose `block` display removes the clamp. With truncation, `wordBreak` defaults to `break-word` for both one line and multiple lines; callers can pass `break-all` when splitting inside words is intentional. When the text is measured as truncated and `hasTruncateTooltip` is not `false`, a lazily loaded Tooltip anchored to the heading shows the full text at the given placement (default `above`); no native `title` is added. `hasTruncateTooltip={false}` takes no measurement. A truncation tooltip can be opened from the keyboard (WCAG 2.2 2.1.1). Implementation gap: the tooltip opens on hover and touch only, because the heading is not focusable (Current-state impact). | Current source and tests |
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
| FR5 | `ref` reaches the heading element. Supported DOM, ARIA, data, and event props reach it after the derived `aria-level`, so a caller `aria-level` wins; `xstyle`, `className`, and `style` merge in that order after component styles, with the line clamp applied after `style`. | Current source and tests |

### Allowed variation
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/components/Text/Text.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR1 | Text renders one element chosen by `as` (default `span`) carrying the `text` target, which reflects `type`, `size`, and the resolved `color`. | Current source and tests |
| FR2 | A built-in `type` applies its size, line height, and default weight; a theme-added type applies the body baseline. `size` overrides the type's size while keeping its other properties; `weight` overrides the type's default weight. The resolved color is `color`, else the type's default; a theme-added color applies the primary baseline. | Current source and tests |
| FR3 | `hasCapsize` renders `block` and trims to cap height; otherwise `maxLines` above 1 renders the line-clamp box, `maxLines={1}` renders `block`, and otherwise `display` (default `inline`) applies. `justify` uses logical values; `start`, the default, sets no alignment, so the element follows its container's. `textWrap`, `hasStrikethrough`, and `hasTabularNumbers` apply their text treatments. Without truncation, a token longer than its line wraps, so in ordinary flow the text does not force horizontal scrolling at 320 CSS px (`spec:AST-020` FR1, WCAG 2.2 1.4.10 Reflow). The element's `overflow-wrap` is `break-word`, which keeps min-content, so tables and auto-sized columns lay out ordinary words unchanged; inside a Core container that wraps its content with `anywhere` (CommandPaletteEmpty, Toast, FieldStatus, Banner), it is `anywhere`, as the container's own text is. A flex child needs `min-width: 0` from its container, and a caller's own container that sets `overflow-wrap: anywhere` does not reach the element's text. | Current source and tests |
| FR4 | `maxLines={1}` clips one line with an ellipsis; a larger value clamps to that many lines unless `hasCapsize` is set, whose `block` display removes the clamp. With truncation, `wordBreak` defaults to `break-all` for one line and `break-word` otherwise. When the text is measured as truncated and `hasTruncateTooltip` is not `false`, a lazily loaded Tooltip anchored to the element shows the full text at the given placement (default `above`), and Text adds no native `title`. `hasTruncateTooltip={false}` takes no measurement. A truncation tooltip can be opened from the keyboard (WCAG 2.2 2.1.1). Implementation gap: the tooltip opens on hover and touch only, because the element is not focusable (Current-state impact). Truncation re-measures when the content changes without a resize. | Current source and tests |
| FR4 | `maxLines={1}` clips one line with an ellipsis; a larger value clamps to that many lines unless `hasCapsize` is set, whose `block` display removes the clamp. With truncation, `wordBreak` defaults to `break-word` for both one line and multiple lines; callers can pass `break-all` when splitting inside words is intentional. When the text is measured as truncated and `hasTruncateTooltip` is not `false`, a lazily loaded Tooltip anchored to the element shows the full text at the given placement (default `above`), and Text adds no native `title`. `hasTruncateTooltip={false}` takes no measurement. A truncation tooltip can be opened from the keyboard (WCAG 2.2 2.1.1). Implementation gap: the tooltip opens on hover and touch only, because the element is not focusable (Current-state impact). Truncation re-measures when the content changes without a resize. | Current source and tests |
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
| FR5 | `ref` reaches the element. Supported DOM, ARIA, data, and event props reach it; `xstyle`, `className`, and `style` merge in that order after component styles, with the line clamp applied after `style`. | Current source and tests |

### Allowed variation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function TextWordBreak() {
}}>
<div>
<Text type="label" display="block">
Break-word (default for multi-line)
Break-word (default for all truncation)
</Text>
<div style={{width: 200, border: '1px solid #ccc', padding: 8}}>
<Text type="body" maxLines={2} wordBreak="break-word">
Expand All @@ -25,7 +25,7 @@ export default function TextWordBreak() {
</div>
<div>
<Text type="label" display="block">
Break-all (default for single-line)
Break-all (explicit opt-in)
</Text>
<div style={{width: 200, border: '1px solid #ccc', padding: 8}}>
<Text type="body" maxLines={2} wordBreak="break-all">
Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/Heading/Heading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('Heading long unbroken tokens', () => {
expect(wrapOf(screen.getByText(token))).toBe(DEFAULT_WRAP);
});

it('leaves single-line truncation clipping on one line', () => {
it('keeps single-line truncation on one line by default', () => {
render(
<Heading level={1} maxLines={1}>
{token}
Expand All @@ -331,7 +331,20 @@ describe('Heading long unbroken tokens', () => {
const style = getComputedStyle(screen.getByText(token));
expect(style.whiteSpace).toBe('nowrap');
expect(style.textOverflow).toBe('ellipsis');
expect(style.overflowWrap).not.toBe('break-word');
expect(style.wordBreak).toBe('normal');
expect(style.overflowWrap).toBe('break-word');
});

it('preserves word boundaries when a caller allows the line to wrap', () => {
render(
<Heading level={1} maxLines={1} style={{whiteSpace: 'normal'}}>
{token}
</Heading>,
);
const style = getComputedStyle(screen.getByText(token));
expect(style.whiteSpace).toBe('normal');
expect(style.wordBreak).toBe('normal');
expect(style.overflowWrap).toBe('break-word');
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export interface HeadingProps extends Omit<

/**
* Word break behavior for truncated text.
* @default 'break-all' for maxLines=1, 'break-word' otherwise
* @default 'break-word'
*/
wordBreak?: WordBreak;

Expand Down Expand Up @@ -244,9 +244,9 @@ export function Heading({
? {'aria-level': accessibilityLevel}
: {};

// Resolve wordBreak with smart default
const resolvedWordBreak =
wordBreak ?? (maxLines === 1 ? 'break-all' : 'break-word');
// A single-line clamp already prevents wrapping. Keep the default word
// boundary behavior consistent if a caller later allows the line to wrap.
const resolvedWordBreak = wordBreak ?? 'break-word';
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

// Resolve display - force block when maxLines > 0 or hasCapsize
const resolvedDisplay = maxLines > 0 || hasCapsize ? 'block' : display;
Expand Down
Loading
Loading