Skip to content

Components: migrate Truncate to SCSS module#79446

Merged
ciampo merged 7 commits into
trunkfrom
codex/components-truncate-scss-module
Jun 25, 2026
Merged

Components: migrate Truncate to SCSS module#79446
ciampo merged 7 commits into
trunkfrom
codex/components-truncate-scss-module

Conversation

@ciampo

@ciampo ciampo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Part of #66806

What?

Migrates Truncate away from Emotion styles and onto an SCSS Module.

Why?

This is one of the canary components for the refreshed Emotion migration plan. It validates a small static style migration plus a prop-driven CSS custom property replacement.

How?

  • Replaces the Emotion styles.ts file with style.module.scss.
  • Uses clsx for class composition.
  • Replaces the dynamic numberOfLines Emotion interpolation with --wp-components-truncate-lines.
  • Keeps the one-line word-break exception as an internal SCSS module class, without adding a public data attribute.
  • Keeps polymorphic rendering delegated to View; the View migration remains separate.

Testing Instructions

  • npm run test:unit packages/components/src/truncate/test/index.tsx -- --runInBand
  • npm run lint:js -- packages/components/src/truncate/hook.ts packages/components/src/truncate/test/index.tsx
  • npm run lint:css -- packages/components/src/truncate/style.module.scss
  • ./node_modules/.bin/tsgo --build packages/components/tsconfig.json
  • git diff --check

Testing Instructions for Keyboard

No keyboard-specific behavior changed. Truncate is a non-interactive typography primitive.

Screenshots or screencast

Not applicable; this should preserve the existing visual output.

Use of AI Tools

Used AI assistance to inspect the existing component implementation, apply the migration, and draft this PR description. The changes were reviewed and verified locally.

@github-actions github-actions Bot added the [Package] Components /packages/components label Jun 23, 2026
@ciampo ciampo force-pushed the codex/components-truncate-scss-module branch from 431e26d to 2763488 Compare June 24, 2026 10:56
@github-actions github-actions Bot added [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor [Package] E2E Tests /packages/e2e-tests [Package] Edit Site /packages/edit-site [Package] Style Engine /packages/style-engine [Package] Theme /packages/theme [Package] UI /packages/ui labels Jun 24, 2026
@ciampo ciampo changed the base branch from codex/components-view-polymorphic to trunk June 24, 2026 10:57
@github-actions github-actions Bot removed [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] E2E Tests /packages/e2e-tests [Package] Edit Site /packages/edit-site [Package] Style Engine /packages/style-engine [Package] Theme /packages/theme [Package] UI /packages/ui labels Jun 24, 2026
@ciampo ciampo self-assigned this Jun 24, 2026
@ciampo ciampo added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Size Change: +195 B (0%)

Total Size: 7.51 MB

📦 View Changed
Filename Size Change
build/scripts/components/index.min.js 264 kB +195 B (+0.07%)

compressed-size-action

expect( screen.getByRole( 'heading' ) ).toHaveStyle( {
textOverflow: 'ellipsis',
} );
expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'L…' );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly changed the test here, switching from invoking the auto mode (which relies on CSS text-truncation and can't be tested) to the explicit limit + ellipsizeMode (which actually chanegs the content of the DOM element).

Sidenote: not in scope for this PR, but we should probably retain the whole text content for assistive technology all the time? Something to keep in mind for #77391

@ciampo ciampo marked this pull request as ready for review June 24, 2026 11:47
@ciampo ciampo requested review from a team, ajitbohra, ellatrix and manzoorwanijk as code owners June 24, 2026 11:47
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment thread packages/components/CHANGELOG.md Outdated
Comment thread packages/components/src/truncate/style.module.scss Outdated
Comment thread packages/components/src/truncate/style.module.scss Outdated
Comment thread packages/components/src/truncate/style.module.scss Outdated
Comment thread packages/components/src/truncate/hook.ts
@ciampo ciampo force-pushed the codex/components-truncate-scss-module branch from 70caf03 to 2058bc5 Compare June 25, 2026 11:56
@github-actions

Copy link
Copy Markdown

Flaky tests detected in 2058bc5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28168347114
📝 Reported issues:

@ciampo ciampo merged commit 13c4726 into trunk Jun 25, 2026
45 checks passed
@ciampo ciampo deleted the codex/components-truncate-scss-module branch June 25, 2026 12:55
@github-actions github-actions Bot added this to the Gutenberg 23.6 milestone Jun 25, 2026
SainathPoojary pushed a commit to SainathPoojary/gutenberg that referenced this pull request Jun 29, 2026
* Components: migrate Truncate to SCSS module

* Truncate: Refine SCSS module migration

* Truncate: Update related test expectations

* Text: Check truncate accessible name

* Text: Remove truncation style assertion

* Text: Restore character truncation test

* Truncate: Address SCSS module review feedback

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants