-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting a toggle button's label (#3765)
* Allow setting a toggle button's label Until now CheckBox and RadioButton labels have been fixed after the widgets have been created. Prompted by #3764 and seeing no reasonable reason to not allow updating the labels later on, this adds that ability. * Link the CHANGELOG entries to the PR * Ensure the setter enforces the first-line-only rule too
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 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,36 @@ | ||
"""Test that setting a toggle button's label has the desired effect.""" | ||
|
||
from rich.text import Text | ||
|
||
from textual.app import App, ComposeResult | ||
from textual.widgets import Checkbox, RadioButton, RadioSet | ||
|
||
|
||
class LabelChangeApp(App[None]): | ||
def compose(self) -> ComposeResult: | ||
yield Checkbox("Before") | ||
yield RadioButton("Before") | ||
yield RadioSet("Before") | ||
|
||
|
||
async def test_change_labels() -> None: | ||
"""It should be possible to change the labels of toggle buttons.""" | ||
async with LabelChangeApp().run_test() as pilot: | ||
assert pilot.app.query_one(Checkbox).label == Text("Before") | ||
assert pilot.app.query_one("Screen > RadioButton", RadioButton).label == Text( | ||
"Before" | ||
) | ||
assert pilot.app.query_one("RadioSet > RadioButton", RadioButton).label == Text( | ||
"Before" | ||
) | ||
pilot.app.query_one(Checkbox).label = "After" | ||
pilot.app.query_one("Screen > RadioButton", RadioButton).label = "After" | ||
pilot.app.query_one("RadioSet > RadioButton", RadioButton).label = "After" | ||
await pilot.pause() | ||
assert pilot.app.query_one(Checkbox).label == Text("After") | ||
assert pilot.app.query_one("Screen > RadioButton", RadioButton).label == Text( | ||
"After" | ||
) | ||
assert pilot.app.query_one("RadioSet > RadioButton", RadioButton).label == Text( | ||
"After" | ||
) |