-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(select): watch reactive prompt change (#3701)
* fix(select): allow reactive prompt change * update watcher with new is_mounted check * update only first in option list * update option list only if allow blank * update changelog
- Loading branch information
1 parent
9a9a072
commit d8b0583
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from rich.text import Text | ||
|
||
from textual.app import App | ||
from textual.widgets import Select, Static | ||
from textual.widgets._select import SelectCurrent, SelectOverlay | ||
|
||
|
||
async def test_reactive_prompt_change(): | ||
"""Regression test for https://github.com/Textualize/textual/issues/2983""" | ||
|
||
class SelectApp(App): | ||
def compose(self): | ||
yield Select[int]( | ||
[(str(n), n) for n in range(3)], | ||
prompt="Old prompt", | ||
) | ||
|
||
app = SelectApp() | ||
async with app.run_test() as pilot: | ||
select_widget = pilot.app.query_one(Select) | ||
select_current = select_widget.query_one(SelectCurrent) | ||
select_current_label = select_current.query_one("#label", Static) | ||
select_overlay = select_widget.query_one(SelectOverlay) | ||
|
||
assert select_current_label.renderable == Text("Old prompt") | ||
assert select_overlay._options[0].prompt == Text("Old prompt") | ||
|
||
select_widget.prompt = "New prompt" | ||
assert select_current_label.renderable == Text("New prompt") | ||
assert select_overlay._options[0].prompt == Text("New prompt") | ||
|
||
|
||
async def test_reactive_prompt_change_when_allow_blank_is_false(): | ||
class SelectApp(App): | ||
def compose(self): | ||
yield Select[int]( | ||
[(str(n), n) for n in range(3)], | ||
prompt="Old prompt", | ||
allow_blank=False, | ||
) | ||
|
||
app = SelectApp() | ||
async with app.run_test() as pilot: | ||
select_widget = pilot.app.query_one(Select) | ||
select_current = select_widget.query_one(SelectCurrent) | ||
select_current_label = select_current.query_one("#label", Static) | ||
select_overlay = select_widget.query_one(SelectOverlay) | ||
|
||
assert select_current_label.renderable == Text("0") | ||
assert select_overlay._options[0].prompt == "0" | ||
|
||
select_widget.prompt = "New prompt" | ||
assert select_current_label.renderable == Text("0") | ||
assert select_overlay._options[0].prompt == "0" |