mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* Add regression tests for #3053 * Traverse invisible containers when computing focus chain. At the moment, we were completely bypassing invisible containers which meant that their visible children wouldn't be included in the focus chain. * Make note of removed property. * Add regression test for #3071. * Fix #3071. * Fix regression test for #3053. * Optimize computation of focus chain. Computing the focus chain was relying on the property 'visible' of nodes which may traverse the DOM up to find the visibility of a given node. Instead, we cache the visibility of the nodes we traverse and keep them in a stack, saving some of that computation. Related issues: #3071 Related comments: https://github.com/Textualize/textual/pull/3070#issuecomment-1669683285 * Make test more robust. * Make test more robust. * Short-circuit disabled portions of DOM. If a node is disabled, we will not be focusable, nor will its children, so we can skip it altogether. Related review comment: https://github.com/Textualize/textual/pull/3070/files#r1300292492 * Simplify traversal. The traversal code could be simplified after reordering some lines of code. We also get rid of the visibility stack and instead keep everything in the same stack. Related comments: https://github.com/Textualize/textual/pull/3070#pullrequestreview-1587295458
79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
from textual.app import App, ComposeResult
|
|
from textual.containers import VerticalScroll
|
|
from textual.widget import Widget
|
|
|
|
|
|
async def test_visibility_changes() -> None:
|
|
"""Test changing visibility via code and CSS.
|
|
|
|
See https://github.com/Textualize/textual/issues/1355 as the motivation for these tests.
|
|
"""
|
|
|
|
class VisibleTester(App[None]):
|
|
"""An app for testing visibility changes."""
|
|
|
|
CSS = """
|
|
Widget {
|
|
height: 1fr;
|
|
}
|
|
.hidden {
|
|
visibility: hidden;
|
|
}
|
|
"""
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield VerticalScroll(
|
|
Widget(id="keep"), Widget(id="hide-via-code"), Widget(id="hide-via-css")
|
|
)
|
|
|
|
async with VisibleTester().run_test() as pilot:
|
|
assert pilot.app.query_one("#keep").visible is True
|
|
assert pilot.app.query_one("#hide-via-code").visible is True
|
|
assert pilot.app.query_one("#hide-via-css").visible is True
|
|
|
|
pilot.app.query_one("#hide-via-code").styles.visibility = "hidden"
|
|
await pilot.pause(0)
|
|
assert pilot.app.query_one("#keep").visible is True
|
|
assert pilot.app.query_one("#hide-via-code").visible is False
|
|
assert pilot.app.query_one("#hide-via-css").visible is True
|
|
|
|
pilot.app.query_one("#hide-via-css").set_class(True, "hidden")
|
|
await pilot.pause(0)
|
|
assert pilot.app.query_one("#keep").visible is True
|
|
assert pilot.app.query_one("#hide-via-code").visible is False
|
|
assert pilot.app.query_one("#hide-via-css").visible is False
|
|
|
|
|
|
async def test_visible_is_inherited() -> None:
|
|
"""Regression test for https://github.com/Textualize/textual/issues/3071"""
|
|
|
|
class InheritedVisibilityApp(App[None]):
|
|
CSS = """
|
|
#four {
|
|
visibility: visible;
|
|
}
|
|
|
|
#six {
|
|
visibility: hidden;
|
|
}
|
|
"""
|
|
|
|
def compose(self):
|
|
yield Widget(id="one")
|
|
with VerticalScroll(id="two"):
|
|
yield Widget(id="three")
|
|
with VerticalScroll(id="four"):
|
|
yield Widget(id="five")
|
|
with VerticalScroll(id="six"):
|
|
yield Widget(id="seven")
|
|
|
|
app = InheritedVisibilityApp()
|
|
async with app.run_test():
|
|
assert app.query_one("#one").visible
|
|
assert app.query_one("#two").visible
|
|
assert app.query_one("#three").visible
|
|
assert app.query_one("#four").visible
|
|
assert app.query_one("#five").visible
|
|
assert not app.query_one("#six").visible
|
|
assert not app.query_one("#seven").visible
|