Skip to content

Fix #56818: Toggle 2FA icons based on theme light/dark mode#59268

Open
carolinafquinteiro wants to merge 1 commit intonextcloud:masterfrom
carolinafquinteiro:fix/2fa-icons-visibility
Open

Fix #56818: Toggle 2FA icons based on theme light/dark mode#59268
carolinafquinteiro wants to merge 1 commit intonextcloud:masterfrom
carolinafquinteiro:fix/2fa-icons-visibility

Conversation

@carolinafquinteiro
Copy link
Copy Markdown

@carolinafquinteiro carolinafquinteiro commented Mar 27, 2026

The 2FA setup and backup code icons were not adapting correctly to different themes, leading to visibility issues.

This fix replaces the single static icon with two separate icons: .two-factor-icon-light and .two-factor-icon-dark. It introduces a new SCSS file to toggle visibility based on:

  • The 'data-themes' attribute on the body (manual selection).
  • The 'prefers-color-scheme' media query (system default theme).

Changes:

  • Modified 2FA PHP templates to include light and dark SVG versions.
  • Added twofactor-icons.scss to handle display:none/inline logic.
  • Registered the new stylesheet in the relevant 2FA views.

Summary

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

The 2FA setup and backup code icons were not adapting correctly to
different themes, leading to visibility issues.

This fix replaces the single static icon with two separate icons:
.two-factor-icon-light and .two-factor-icon-dark. It introduces
a new SCSS file to toggle visibility based on:
- The 'data-themes' attribute on the body (manual selection).
- The 'prefers-color-scheme' media query (system default theme).

Changes:
- Modified 2FA PHP templates to include light and dark SVG versions.
- Added twofactor-icons.scss to handle display:none/inline logic.
- Registered the new stylesheet in the relevant 2FA views.

Signed-off-by: Carolina Quinteiro <carolinafquinteiro@tecnico.ulisboa.pt>
@carolinafquinteiro carolinafquinteiro requested review from nfebe, sorbaugh and susnux and removed request for a team March 27, 2026 17:21
Copy link
Copy Markdown
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution!

One question about the implementation:
Why not simplify by just assign this stlye to the icon:

filter: var(--background-invert-if-dark);

@miaulalala
Copy link
Copy Markdown
Contributor

Thanks for your contribution @carolinafquinteiro - could you add some before / after screenshots?

@github-actions
Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@carolinafquinteiro
Copy link
Copy Markdown
Author

Thank you for the suggestion @susnux! I've tested using filter: var(--background-invert-if-dark); but unfortunately it didn't work as expected: the icon remained light even in dark mode. It seems that in this specific guest/login context, the filter isn't being triggered correctly or the variable isn't behaving as intended for these specific assets. That's why I kept the current implementation to ensure it works reliably across all themes.

@carolinafquinteiro
Copy link
Copy Markdown
Author

Hi @miaulalala,

Thank you for your feedback. As requested, here are the screenshots showing the visibility issue and the fix I implemented.

In the first image, you can see that the icon is nearly invisible due to the white-on-white contrast. My PR ensures the icon remains visible by correctly switching between the light and dark versions.

Issue (White on White):

Corrected:

@miaulalala
Copy link
Copy Markdown
Contributor

Fantastic - can you rebase your PR on the most current master please?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The icons for 2FA providers remain white regardless of whether the theme is dark or light

4 participants