diff --git a/src/textual/css/model.py b/src/textual/css/model.py index c5efebc153..ed9db4df84 100644 --- a/src/textual/css/model.py +++ b/src/textual/css/model.py @@ -108,7 +108,7 @@ def _check_class(self, node: DOMNode) -> bool: return True def _check_id(self, node: DOMNode) -> bool: - if not node.id == self._name_lower: + if (node._cmp_id is None) or (node._cmp_id.lower() != self._name_lower): return False if self.pseudo_classes and not node.has_pseudo_class(*self.pseudo_classes): return False diff --git a/src/textual/dom.py b/src/textual/dom.py index 1a35b07176..54a3d555e9 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -121,6 +121,7 @@ def __init__( self._classes = set() self._name = name self._id = None + self._cmp_id = None if id is not None: self.id = id @@ -308,6 +309,7 @@ def id(self, new_id: str) -> str: f"Node 'id' attribute may not be changed once set (current id={self._id!r})" ) self._id = new_id + self._cmp_id = new_id.lower() return new_id @property diff --git a/tests/test_query.py b/tests/test_query.py index 13d5bc5b4e..ebc9c0247c 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -18,7 +18,7 @@ class App(Widget): app._add_child(help_view) widget1 = Widget(id="widget1") - widget2 = Widget(id="widget2") + widget2 = Widget(id="Widget2") # Note case. sidebar = Widget(id="sidebar") sidebar.add_class("float") @@ -54,7 +54,9 @@ class App(Widget): assert list(app.query("#main")) == [main_view] assert list(app.query("View#main")) == [main_view] assert list(app.query("#widget1")) == [widget1] + assert list(app.query("#Widget1")) == [widget1] # Note case. assert list(app.query("#widget2")) == [widget2] + assert list(app.query("#Widget2")) == [widget2] # Note case. assert list(app.query("Widget.float")) == [sidebar, tooltip, helpbar] assert list(app.query(Widget).filter(".float")) == [sidebar, tooltip, helpbar]