Jelajahi Sumber

fix style definitions with trailing semicolon #93

Falko Schindler 2 tahun lalu
induk
melakukan
b54f827cef
2 mengubah file dengan 4 tambahan dan 1 penghapusan
  1. 1 1
      nicegui/elements/element.py
  2. 3 0
      tests/test_element.py

+ 1 - 1
nicegui/elements/element.py

@@ -70,7 +70,7 @@ class Element:
         This can be helpful if the predefined style sheet definitions by NiceGUI are not wanted in a particular styling.
         This can be helpful if the predefined style sheet definitions by NiceGUI are not wanted in a particular styling.
         '''
         '''
         def str_to_dict(s: Optional[str]) -> Dict[str, str]:
         def str_to_dict(s: Optional[str]) -> Dict[str, str]:
-            return dict((word.strip() for word in part.split(':')) for part in s.split(';')) if s else {}
+            return dict((word.strip() for word in part.split(':')) for part in s.strip('; ').split(';')) if s else {}
         style_dict = str_to_dict((self.view.style or '').strip('; ')) if replace is None else {}
         style_dict = str_to_dict((self.view.style or '').strip('; ')) if replace is None else {}
         for key in str_to_dict(remove):
         for key in str_to_dict(remove):
             del style_dict[key]
             del style_dict[key]

+ 3 - 0
tests/test_element.py

@@ -68,6 +68,9 @@ def test_style(user: User):
     label.style(replace='text-decoration: underline')
     label.style(replace='text-decoration: underline')
     assert_style('text-decoration: underline;')
     assert_style('text-decoration: underline;')
 
 
+    label.style('color: blue;')
+    assert_style('text-decoration: underline; color: blue;')
+
 
 
 def test_props(user: User):
 def test_props(user: User):
     input = ui.input()
     input = ui.input()