Skip to content

Commit

Permalink
#1293 fix ui.query with CSS variables
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 1, 2023
1 parent fe85efe commit 8df7d25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nicegui/elements/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
},
add_style(style) {
Object.entries(style).forEach(([key, val]) =>
document.querySelectorAll(this.selector).forEach((e) => (e.style[key] = val))
document.querySelectorAll(this.selector).forEach((e) => e.style.setProperty(key, val))
);
},
remove_style(keys) {
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from nicegui import Client, globals
from nicegui.elements import plotly, pyplot
Expand Down
8 changes: 8 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ def test_query_multiple_divs(screen: Screen):
screen.wait(0.5)
assert screen.find('A').value_of_css_property('border') == '1px solid rgb(0, 0, 0)'
assert screen.find('B').value_of_css_property('border') == '1px solid rgb(0, 0, 0)'


def test_query_with_css_variables(screen: Screen):
ui.add_body_html('<div id="element">Test</div>')
ui.query('#element').style('--color: red; color: var(--color)')

screen.open('/')
assert screen.find('Test').value_of_css_property('color') == 'rgba(255, 0, 0, 1)'

0 comments on commit 8df7d25

Please sign in to comment.