{"record":{"id":"38abcdfd4cd484a4","repo":"Textualize/textual","slug":"invalid-value-for-visibility-received-new-value","errorCode":null,"errorMessage":"invalid value for visibility (received {new_value!r}, expected {friendly_list(VALID_VISIBILITY)})","messagePattern":"invalid value for visibility \\(received (.+?), expected (.+?)\\)","errorType":"validation","errorClass":"StyleValueError","httpStatus":null,"severity":"error","filePath":"src/textual/dom.py","lineNumber":963,"sourceCode":"        This may be set explicitly to override inherited values.\n        The valid values include the valid values for the `visibility` rule and the booleans\n        `True` or `False`, to set the widget to be visible or invisible, respectively.\n\n        When a node is invisible, Textual will reserve space for it, but won't display anything.\n        \"\"\"\n        own_value = self.styles.get_rule(\"visibility\")\n        if own_value is not None:\n            return own_value != \"hidden\"\n        return self.parent.visible if self.parent else True\n\n    @visible.setter\n    def visible(self, new_value: bool | str) -> None:\n        if isinstance(new_value, bool):\n            self.styles.visibility = \"visible\" if new_value else \"hidden\"\n        elif new_value in VALID_VISIBILITY:\n            self.styles.visibility = new_value\n        else:\n            raise StyleValueError(\n                f\"invalid value for visibility (received {new_value!r}, \"\n                f\"expected {friendly_list(VALID_VISIBILITY)})\"\n            )\n\n    @property\n    def tree(self) -> Tree:\n        \"\"\"A Rich tree to display the DOM.\n\n        Log this to visualize your app in the textual console.\n\n        Example:\n            ```python\n            self.log(self.tree)\n            ```\n\n        Returns:\n            A Tree renderable.\n        \"\"\"","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/dom.py#L945-L981","documentation":"The visible setter accepts booleans or a valid CSS visibility keyword ('visible', 'hidden'); other values raise StyleValueError listing the accepted values.","triggerScenarios":"Assigning widget.visible = 'collapse', 'initial', None, or any string not in VALID_VISIBILITY.","commonSituations":"Confusing CSS visibility keywords from web CSS (which has more values) with textual's subset; passing through unvalidated user/config-driven strings.","solutions":["Use True/False (mapped to 'visible'/'hidden') or one of the documented VALID_VISIBILITY strings","Validate dynamic strings against VALID_VISIBILITY from textual.css.constants before assignment"],"exampleFix":"# before\nwidget.visible = 'collapse'  # StyleValueError\n\n# after\nwidget.visible = False  # or 'hidden' / 'visible'","handlingStrategy":"type-guard","validationCode":"from textual.css.constants import VALID_VISIBILITY\n\ndef set_visible(widget, value):\n    if isinstance(value, bool) or value in VALID_VISIBILITY:\n        widget.visible = value\n    else:\n        widget.visible = bool(value)","typeGuard":"from textual.css.constants import VALID_VISIBILITY\ndef is_valid_visibility(v) -> bool:\n    return isinstance(v, bool) or (isinstance(v, str) and v in VALID_VISIBILITY)","tryCatchPattern":"try:\n    widget.visible = value\nexcept StyleValueError:\n    widget.visible = True  # fallback to default visible","preventionTips":["Use booleans for visible/hidden","Whitelist dynamic strings against VALID_VISIBILITY","Don't assume web-CSS visibility keywords exist"],"tags":["textual","visibility","styles","validation"],"backgroundTag":"invalid-css-style-value","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}