Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use current dark/light mode for btns in labelauty #718

Merged
merged 2 commits into from
Dec 1, 2023

Conversation

BryceStevenWilley
Copy link
Contributor

@BryceStevenWilley BryceStevenWilley commented Dec 1, 2023

Otherwise, the buttons stand out and don't match the rest of the requested theme. To avoid DOM XSS issues, we check if data-bs-theme is dark, and use the string "dark" if it is. Otherwise (if for some reason there isn't a data-bs-theme on the document, or it's some string we don't recognize), we default to light mode.

This, along with #717 fixes some issues with trying to make a dark mode theme.

Some images of the differences here:

  • Pre-PR radio buttons and checkboxes in dark mode:

    Screenshot from 2023-12-01 15-40-47

  • Post-PR radio buttons and checkboxes in dark mode:

    Screenshot from 2023-12-01 15-38-48

Otherwise, the buttons stand out and don't match the rest of the requested
theme.

If for some reason there isn't a `data-bs-theme` on the document, default to
light mode.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

There were a few issues in the CodeQL check, but this is the only one introduced
in this PR.

Instead of directly taking the `data-bs-theme` from the DOM, we can simply
check if the theme is dark, and use the string "dark". Otherwise, we use
"light", which prevents any direct DOM XSS issues.

https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html

The full CodeQL run: https://github.com/jhpyle/docassemble/pull/718/checks?check_run_id=19234176736
@jhpyle jhpyle merged commit 9c7cfa0 into jhpyle:master Dec 1, 2023
2 of 3 checks passed
@jhpyle
Copy link
Owner

jhpyle commented Dec 2, 2023

I am not sure that JavaScript should be used to change CSS classes based on light/dark mode. The user needs to be able to change the light/dark mode and see the changes immediately without having to reload the screen or retrigger JavaScript. The JavaScript solution might not work for labelauty lists that appear on the initial page the user sees, because of the way the mode gets activated by JavaScript code. There could be other issues as well that arise from using JavaScript to do CSS's job.

The underlying problem is that Bootstrap is missing a feature, but the feature is apparently on its way:
twbs/bootstrap#38748

In the meantime there is a CSS workaround that users can implement easily themselves (copying and pasting the .btn-dark CSS):

[data-bs-theme=dark] .btn-light.dalabelauty {
  --bs-btn-color: #fff;
  --bs-btn-bg: #212529;
  --bs-btn-border-color: #212529;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #424649;
  --bs-btn-hover-border-color: #373b3e;
  --bs-btn-focus-shadow-rgb: 66, 70, 73;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #4d5154;
  --bs-btn-active-border-color: #373b3e;
  --bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #212529;
  --bs-btn-disabled-border-color: #212529;
}

@BryceStevenWilley
Copy link
Contributor Author

I am not sure that JavaScript should be used to change CSS classes based on light/dark mode. The user needs to be able to change the light/dark mode and see the changes immediately without having to reload the screen or retrigger JavaScript.

I agree that it should be a CSS thing, but that's not how changing the theme works at the moment. If you change the browser theme / appearance, you have to refresh the DA page for it to take affect. I see what you mean though, changing the theme in multiple places vs having everything be dependent on data-bs-theme. The workaround solves the issue for now.

@BryceStevenWilley BryceStevenWilley deleted the labelauty-dark-mode branch December 4, 2023 15:05
BryceStevenWilley added a commit to SuffolkLITLab/docassemble-ALToolbox that referenced this pull request Dec 4, 2023
In dark mode, the display templates still have a light background, and stand
out far too much. This adds CSS to change the `bg-light` class for the collapse
and display templates to the dark-mode colors when `data-bs-theme=dark`.

See jhpyle/docassemble#718 for a discussion on a
suggested fix for a similar issue, which resulted in the suggested workaround
here.
BryceStevenWilley added a commit to SuffolkLITLab/docassemble-ALToolbox that referenced this pull request Dec 5, 2023
In dark mode, the display templates still have a light background, and stand
out far too much. This adds CSS to change the `bg-light` class for the collapse
and display templates to the dark-mode colors when `data-bs-theme=dark`.

See jhpyle/docassemble#718 for a discussion on a
suggested fix for a similar issue, which resulted in the suggested workaround
here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants