Skip to content

Bugfix: Keep toggle switch X icon centered at all browser zoom levels - #2572

Open
az108 wants to merge 7 commits into
mainfrom
bugfix/toggle-switch-icon-centering
Open

Bugfix: Keep toggle switch X icon centered at all browser zoom levels#2572
az108 wants to merge 7 commits into
mainfrom
bugfix/toggle-switch-icon-centering

Conversation

@az108

@az108 az108 commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • I documented the TypeScript code using JSDoc style.

Motivation and Context

Closes #2569.

The X icon inside the toggle switch handle drifted off-center at non-100% browser zoom levels (60%, 80%, 120%, 150%). At 100% the icon looked roughly centered, but at other zoom levels it sat noticeably above or below the visual centre of the handle, making the component feel unpolished.

Description

The handle (.p-toggleswitch-handle) was already flex items-center justify-center, so flex centering was wired up correctly. The drift came from <fa-icon> itself rendering as inline content: its bounding box included font-baseline metrics from the line box, and at non-integer zoom factors the browser's sub-pixel rounding aligned that baseline-derived box differently in the vertical axis than the horizontal axis. The result was a visible vertical shift that changed with zoom.

The fix removes the baseline geometry from the chain:

  • Make <fa-icon> itself a flex container (flex items-center justify-center) so its inner SVG is centred geometrically inside it instead of via inline-text alignment.
  • Make the inner <svg> block ([&>svg]:block) so it is no longer subject to baseline alignment within the fa-icon wrapper.

With both inline-baseline alignments removed, centering depends only on flexbox geometry, which is stable across zoom levels.

No test was added: the change is purely about visual centering at fractional zoom levels, which jsdom cannot meaningfully assert. The behaviour is verified manually per the steps below.

Steps for Testing

Prerequisites:

  1. Log in to TUMApply.
  2. Open a screen that renders the toggle switch — e.g. Admin → System Settings, or any settings page with notification/AI consent toggles.
  3. Toggle the switch off so the red handle with the X icon is visible.
  4. Set the browser zoom to 60% and confirm the X is visually centred inside the handle (no vertical or horizontal drift).
  5. Repeat at 80%, 100%, 120%, and 150%.
  6. Toggle the switch on (green handle with check icon) and repeat at the same zoom levels — the check should also remain centred.

Review Progress

Code Review

  • Code Review 1

Manual Tests

  • X icon centred at 60% zoom
  • X icon centred at 100% zoom
  • X icon centred at 150% zoom
  • Check icon (toggle on) centred at the same zoom levels

Screenshots

To be added by the reviewer after manual verification across zoom levels.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the client Pull requests that update TypeScript code. (Added Automatically!) label May 23, 2026
@codacy-production

codacy-production Bot commented May 23, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@Cathy0123456789 Cathy0123456789 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have the feeling this didn't quite fix it 😅
Image

@github-actions

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

az108 and others added 2 commits July 4, 2026 23:46
Flex centering left the icon with ~1px of vertical slack inside the short
elliptical handle; the browser snapped that slack to whole device pixels
inconsistently across zoom levels, so the icon drifted vertically. Absolute
positioning with translate(-50%, -50%) centers in a single step with no margin
rounding, keeping the icon centered at all zoom levels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests that update TypeScript code. (Added Automatically!) ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X icon within toggle button is not centered consistently across browser zoom levels

2 participants