Skip to content

fix(Button): prevent text wrap in constrained layouts - #892

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/button-text-nowrap
Mar 26, 2026
Merged

fix(Button): prevent text wrap in constrained layouts#892
cixzhang merged 1 commit into
mainfrom
navi/fix/button-text-nowrap

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Problem

Button text wraps to a second line when placed in constrained flex layouts, causing the icon to appear disproportionately large.

Spotted by @cixzhang in #888 — the "New item" button in the WithActions TabList story wraps at narrow viewports:

Screenshot

Fix

Two changes to the button base styles:

  1. whiteSpace: 'nowrap' on the button container — prevents text from wrapping to a second line
  2. Label text wrapper with overflow: hidden + textOverflow: ellipsis — so constrained buttons truncate with an ellipsis instead of clipping silently

Story

Adds a Truncation story to Core/XDSButton demonstrating:

  • 200px container with a long label → truncates with ellipsis
  • Flex row with limited space → button shrinks gracefully
  • Unconstrained → renders at natural width

@cixzhang
cixzhang requested a review from josephfarina as a code owner March 25, 2026 23:45
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 25, 2026
@github-actions

github-actions Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Button · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 394B N/A
Lines of Code N/A 380 -
Complexity N/A Very High (39) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 11.0KB 17.6KB 2.7KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

Add whiteSpace: 'nowrap' to button base styles so text never wraps to
a second line. Wrap the label text in a span with overflow: hidden and
textOverflow: ellipsis so constrained buttons truncate gracefully
instead of clipping silently.

Adds a Truncation story demonstrating the behavior at various widths.

Co-authored-by: Navi <navi@navibot.dev>
@cixzhang
cixzhang force-pushed the navi/fix/button-text-nowrap branch from 9a3d6ab to f98a6dc Compare March 25, 2026 23:58
@cixzhang
cixzhang merged commit ae64720 into main Mar 26, 2026
14 checks passed
@cixzhang
cixzhang deleted the navi/fix/button-text-nowrap branch April 9, 2026 14:32
cixzhang added a commit that referenced this pull request Apr 26, 2026
Add whiteSpace: 'nowrap' to button base styles so text never wraps to
a second line. Wrap the label text in a span with overflow: hidden and
textOverflow: ellipsis so constrained buttons truncate gracefully
instead of clipping silently.

Adds a Truncation story demonstrating the behavior at various widths.

Co-authored-by: Navi <navi@users.noreply.github.com>
cixzhang added a commit that referenced this pull request Jun 21, 2026
Add whiteSpace: 'nowrap' to button base styles so text never wraps to
a second line. Wrap the label text in a span with overflow: hidden and
textOverflow: ellipsis so constrained buttons truncate gracefully
instead of clipping silently.

Adds a Truncation story demonstrating the behavior at various widths.

Co-authored-by: Navi <navi@users.noreply.github.com>
cixzhang added a commit that referenced this pull request Jun 21, 2026
Add whiteSpace: 'nowrap' to button base styles so text never wraps to
a second line. Wrap the label text in a span with overflow: hidden and
textOverflow: ellipsis so constrained buttons truncate gracefully
instead of clipping silently.

Adds a Truncation story demonstrating the behavior at various widths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant