-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(text area)!: stop escape shifting focus if default tab behaviour (#…
…4125) * fix(text area): stop escape shifting focus if default tab behaviour * fix recent update to changelog * address review feedback * update changelog
- Loading branch information
1 parent
5d6c61a
commit e27c41c
Showing
4 changed files
with
75 additions
and
9 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
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,55 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.screen import ModalScreen | ||
from textual.widgets import Button, TextArea | ||
|
||
|
||
class TextAreaDialog(ModalScreen): | ||
BINDINGS = [("escape", "dismiss")] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield TextArea( | ||
tab_behaviour="focus", # the default | ||
) | ||
yield Button("Submit") | ||
|
||
|
||
class TextAreaDialogApp(App): | ||
def on_mount(self) -> None: | ||
self.push_screen(TextAreaDialog()) | ||
|
||
|
||
async def test_escape_key_when_tab_behaviour_is_focus(): | ||
"""Regression test for https://github.com/Textualize/textual/issues/4110 | ||
When the `tab_behaviour` of TextArea is the default to shift focus, | ||
pressing <Escape> should not shift focus but instead skip and allow any | ||
parent bindings to run. | ||
""" | ||
|
||
app = TextAreaDialogApp() | ||
async with app.run_test() as pilot: | ||
# Sanity check | ||
assert isinstance(pilot.app.screen, TextAreaDialog) | ||
assert isinstance(pilot.app.focused, TextArea) | ||
|
||
# Pressing escape should dismiss the dialog screen, not focus the button | ||
await pilot.press("escape") | ||
assert not isinstance(pilot.app.screen, TextAreaDialog) | ||
|
||
|
||
async def test_escape_key_when_tab_behaviour_is_indent(): | ||
"""When the `tab_behaviour` of TextArea is indent rather than switch focus, | ||
pressing <Escape> should instead shift focus. | ||
""" | ||
|
||
app = TextAreaDialogApp() | ||
async with app.run_test() as pilot: | ||
# Sanity check | ||
assert isinstance(pilot.app.screen, TextAreaDialog) | ||
assert isinstance(pilot.app.focused, TextArea) | ||
|
||
pilot.app.query_one(TextArea).tab_behaviour = "indent" | ||
# Pressing escape should focus the button, not dismiss the dialog screen | ||
await pilot.press("escape") | ||
assert isinstance(pilot.app.screen, TextAreaDialog) | ||
assert isinstance(pilot.app.focused, Button) |