Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/textual/_text_area_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def apply_css(self, text_area: TextArea) -> None:
text_area: The TextArea instance to retrieve fallback styling from.
"""
self.base_style = text_area.rich_style or Style()
get_style = text_area.get_component_rich_style
def get_style(name: str) -> Style | None:
try:
return text_area.get_component_rich_style(name)
except KeyError:
return None

if self.base_style.color is None:
self.base_style = Style(color="#f3f3f3", bgcolor=self.base_style.bgcolor)
Expand Down
41 changes: 41 additions & 0 deletions tests/text_area/test_issue_6528.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.screen import ModalScreen
from textual.widgets import TextArea


class CredsModal(ModalScreen[None]):
CSS = """
#box {
width: 80;
height: 20;
border: heavy white;
}
#ta {
height: 10;
border: solid white;
}
"""

def compose(self) -> ComposeResult:
with Container(id="box"):
yield TextArea("", id="ta", language=None, show_line_numbers=False)


class Demo(App):
def on_mount(self) -> None:
self.push_screen(CredsModal())


@pytest.mark.asyncio
async def test_issue_6528_modal_textarea_no_crash():
app = Demo()
async with app.run_test() as pilot:
# Pushing a ModalScreen and rendering the TextArea inside should not crash
await pilot.pause()
ta = app.screen.query_one(TextArea)
assert ta is not None
# Call render_lines explicitly to ensure apply_css is executed
from textual.geometry import Region
ta.render_lines(Region(0, 0, 80, 10))