Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Proposed changes

The px-to-rem() and px-to-em() functions returned strings via interpolation (#{...}rem), preventing calculations with their output. Changed to return properly typed values by multiplying the numeric result by 1rem/1em.

Before:

@function px-to-rem($pxValue) {
  @return #{$pxValue * 0.0625}rem;  // Returns string "1rem"
}

$spacing: px-to-rem(16) * 2;  // ❌ Error: Undefined operation "1rem * 2"

After:

@function px-to-rem($pxValue) {
  @return ($pxValue * 0.0625) * 1rem;  // Returns typed rem value
}

$spacing: px-to-rem(16) * 2;  // ✅ Returns 2rem

String interpolation (#{px-to-rem(24)}) continues to work unchanged.

Types of changes

  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improvements to existing components or architectural decisions)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Further comments

Both functions now return SASS typed values compatible with arithmetic operations while maintaining backward compatibility with existing string interpolation usage throughout the codebase.

Original prompt

This section details on the original issue you should resolve

<issue_title>px-to-rem() returns a string instead of a rem value</issue_title>
<issue_description>### Which generators are affected?

  • All
  • HTML
  • React
  • Angular
  • Vue
  • Web components
  • Power Apps

Reproduction case

The current implementation of px-to-rem() does not return a value but a string. I stumbled upon this issue while creating a very similar function in our code. The way it is currently implemented does not allow calculations with the value:

@function px-to-rem($pxValue) {
@return #{$pxValue * 0.0625}rem;
}

Expected Behaviour

The return value should be a rem value, therefore the function neede to be adjusted in this way:

instead of: @return #{$pxValue * 0.0625}rem;
use this: @return ($pxValue * 0.0625) * 1rem;

For completeness, I also found it here: sass/sass#2356 (comment)

Screenshots

No response

Browser version

None

Add any other context about the problem here.

No response

Which DB business unit do you work for?

Delivery-Team Web Development 1 (TO.IP D-T-037)

”DB Systel” please enter your customer / ”other” please enter your area or business unit.

No response

What project are you working on?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

🔭🐙🐈 Test this branch here: https://design-system.deutschebahn.com/core-web/review/copilot/fix-px-to-rem-function

@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: 46027e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@db-ux/core-foundations Patch
@db-ux/core-components Patch
@db-ux/ngx-core-components Patch
@db-ux/react-core-components Patch
@db-ux/wc-core-components Patch
@db-ux/v-core-components Patch
@db-ux/core-stylelint Patch
@db-ux/core-migration Patch
@db-ux/agent-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…trings

Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix px-to-rem() to return a rem value fix: Return typed values from px-to-rem() and px-to-em() instead of strings Dec 4, 2025
Copilot AI requested a review from mfranzke December 4, 2025 06:09
Copilot finished work on behalf of mfranzke December 4, 2025 06:09
@mfranzke mfranzke marked this pull request as ready for review December 4, 2025 06:13
@mfranzke mfranzke added the 🐛bug Something isn't working label Dec 4, 2025
@mfranzke mfranzke moved this from 🏗 In progress to 🎁 Ready for review in UX Engineering Team Backlog Dec 4, 2025
@mfranzke mfranzke changed the title fix: Return typed values from px-to-rem() and px-to-em() instead of strings fix: Return typed values from scss functions instead of strings Dec 4, 2025
@mfranzke mfranzke enabled auto-merge (squash) December 4, 2025 06:20
@mfranzke mfranzke disabled auto-merge December 4, 2025 10:10
@github-actions github-actions bot added the 📕documentation Improvements or additions to documentation label Dec 4, 2025
@mfranzke mfranzke requested a review from Copilot December 4, 2025 11:59
Copilot finished reviewing on behalf of mfranzke December 4, 2025 12:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the px-to-rem() and px-to-em() SCSS helper functions that returned string values instead of properly typed Sass values, preventing arithmetic operations on their output. The fix changes from string interpolation (#{...}rem) to proper type multiplication (* 1rem), enabling calculations while maintaining backward compatibility.

Key changes:

  • Modified px-to-rem() to return typed rem values by multiplying the result by 1rem
  • Modified px-to-em() to return typed em values by multiplying the result by 1em
  • Added changeset documenting the bug fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/foundations/scss/helpers/_functions.scss Fixed px-to-rem() and px-to-em() functions to return typed values instead of strings by replacing string interpolation with proper multiplication
.changeset/heavy-spiders-check.md Added changeset file to document the bug fix for the affected packages

@mfranzke mfranzke changed the title fix: Return typed values from scss functions instead of strings fix: return typed values from scss functions instead of strings Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working 📕documentation Improvements or additions to documentation 🏗foundations

Projects

Status: 🎁 Ready for review

Development

Successfully merging this pull request may close these issues.

px-to-rem() returns a string instead of a rem value

2 participants