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

Fix iframe background for dark color scheme #7821

Merged
merged 5 commits into from Dec 11, 2023

Conversation

LukasMasuch
Copy link
Collaborator

@LukasMasuch LukasMasuch commented Dec 8, 2023

Describe your changes

This PR fixes an issue with iframes where the background uses white instead of transparent if a dark background is configured. This only happens in Firefox and Safari; Chrome uses the correct background.

The reason is that we recently added the color-schema keyword to indicate the browser if the app is in dark or light mode. But this triggers an automatic behavior where the browsers adds a white background to iframes since it assumes that the iframe can only handle a light background. We have to tell the iframe that the iframe supports both light and dark color schemes to fix this.

GitHub Issue Link (if applicable)

Testing Plan

  • Migrates e2e components test to playwright to also cover firefox and safari browsers.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@LukasMasuch LukasMasuch marked this pull request as ready for review December 9, 2023 15:50
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this correct, that dark theme text in the iframe has black color?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we don't do anything to automatically change styles within the iframe. That is something a developer would need to take care of. For example, custom components get theme information injected.

@LukasMasuch LukasMasuch merged commit 1bf98d0 into develop Dec 11, 2023
44 checks passed
@hoanq1811
Copy link

hoanq1811 commented Jan 15, 2024

Hi @LukasMasuch
I upgraded it to the latest version (v1.30.0) but:
The white background still appears when I embed a customization table with the dark mode configuration on Chrome on macOS M1.
You can take a look the issue below:
image

This is my code:

table_html = f"""
<div style="position: relative;">
   <div id="copy-button-container">
        <button class="copy-button" id="btn-copy" style="float:right;">
            <img src="https://img.icons8.com/material-rounded/24/000000/copy.png"/>
        </button>
   </div>
   <table>
      <tr>
          <th>Calendar Year</th>
          <th>Volume</th>
     <tr>
     <tr>
          <th>12.32</th>
          <th>12.32</th>
     <tr>
   </table>
</div>
"""
    
# JavaScript code for clipboard.js
clipboard_js = """
    <script type="text/javascript">
        document.getElementById("btn-copy").addEventListener("click", function() {
            var table = document.getElementById('st-custom-table');
            var range = document.createRange();
            range.selectNode(table);
            window.getSelection().addRange(range);
            var successful = document.execCommand('copy');
            window.getSelection().removeAllRanges();
            if (successful) {
                alert('Table copied to clipboard!');
            } else {
                alert('Unable to copy table.');
            }
        });
    </script>
"""
# Display the custom CSS and JavaScript
st.components.v1.html(table_html + clipboard_js, scrolling=True)

Same issue when I try running the sample code on the document site: https://docs.streamlit.io/library/components/components-api

  • Streamlit version: 1.30.0
  • MacOS: Sonoma, Version: 14.0
  • Chrome: 120.0.6099.62 (arm64)

@LukasMasuch LukasMasuch deleted the fix/iframe-color-scheme branch January 23, 2024 00:22
@erikvanzijst
Copy link

erikvanzijst commented Feb 23, 2024

hoanq1811

Same for me, not fixed (1.31.0 on M1 Mac in Chrome & Safari).

CC @LukasMasuch

image

@LukasMasuch
Copy link
Collaborator Author

@hoanq1811 I deployed the code here. But the issue is not reproducible for me in 1.31 (the background is transparent and not white):

image

@LukasMasuch
Copy link
Collaborator Author

@erikvanzijst Do you have a code snippet for this to help with reproducing this issue?

LukasMasuch added a commit that referenced this pull request Mar 18, 2024
## Describe your changes

I previously attempted to fix this issue in
#7821. This fix worked fine,
but only if the OS isn't configured to dark mode (+ Chrome). This fix
sets the color scheme to `normal` to indicate that the element isn't
aware of any color schemes. This seems to provide us with the desired
behaviour to not automatically show a white background.

## GitHub Issue Link (if applicable)

Closes #8156
Closes #7813

## Testing Plan

- The test should be fine to cover this. 

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
* Add color scheme property to iframes

* Add scheme to all iframes

* Update snapshots

* Migrate components e2e tests

* Add snapshots
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
…it#8242)

## Describe your changes

I previously attempted to fix this issue in
streamlit#7821. This fix worked fine,
but only if the OS isn't configured to dark mode (+ Chrome). This fix
sets the color scheme to `normal` to indicate that the element isn't
aware of any color schemes. This seems to provide us with the desired
behaviour to not automatically show a white background.

## GitHub Issue Link (if applicable)

Closes streamlit#8156
Closes streamlit#7813

## Testing Plan

- The test should be fine to cover this. 

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
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.

streamlit v1.29.0 sets white backround to html component which is impossible to change (e.g. make transparent)
4 participants