diff --git a/nicegui/element.py b/nicegui/element.py index 3cb5479ef..0375b454d 100644 --- a/nicegui/element.py +++ b/nicegui/element.py @@ -98,7 +98,13 @@ def classes(self, add: Optional[str] = None, *, remove: Optional[str] = None, re @staticmethod def _parse_style(text: Optional[str]) -> Dict[str, str]: - return dict(_split(part, ':') for part in text.strip('; ').split(';')) if text else {} + result = {} + for word in (text or '').split(';'): + word = word.strip() + if word: + key, value = word.split(':', 1) + result[key.strip()] = value.strip() + return result def style(self, add: Optional[str] = None, *, remove: Optional[str] = None, replace: Optional[str] = None): '''CSS style sheet definitions to modify the look of the element. @@ -211,8 +217,3 @@ def delete(self) -> None: Can be overridden to perform cleanup. """ - - -def _split(text: str, separator: str) -> Tuple[str, str]: - words = text.split(separator, 1) - return words[0].strip(), words[1].strip() diff --git a/tests/test_element.py b/tests/test_element.py index 19567ad2c..7e32e93ad 100644 --- a/tests/test_element.py +++ b/tests/test_element.py @@ -34,6 +34,7 @@ def assert_classes(classes: str) -> None: def test_style_parsing(): + assert Element._parse_style(None) == {} assert Element._parse_style('color: red; background-color: green') == {'color': 'red', 'background-color': 'green'} assert Element._parse_style('width:12em;height:34.5em') == {'width': '12em', 'height': '34.5em'} assert Element._parse_style('transform: translate(120.0px, 50%)') == {'transform': 'translate(120.0px, 50%)'}