Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datatable): prevent crash with border link #4415

Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## Unreleased

### Fixed

- Fixed a crash in `DataTable` if you clicked a link in the border https://github.com/Textualize/textual/issues/4410

### Added

- Added `App.copy_to_clipboard` https://github.com/Textualize/textual/pull/4416
Expand Down
2 changes: 1 addition & 1 deletion src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ def _set_hover_cursor(self, active: bool) -> None:
async def _on_click(self, event: events.Click) -> None:
self._set_hover_cursor(True)
meta = event.style.meta
if not meta:
if not "row" in meta or not "column" in meta:
return

row_index = meta["row"]
Expand Down
30 changes: 29 additions & 1 deletion tests/test_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from textual._wait import wait_for_idle
from textual.actions import SkipAction
from textual.app import App, RenderableType
from textual.app import App, ComposeResult, RenderableType
from textual.coordinate import Coordinate
from textual.geometry import Offset
from textual.message import Message
Expand Down Expand Up @@ -1420,3 +1420,31 @@ def key_s(self):
await pilot.press("s")

assert scrolls == [True, False]


async def test_clicking_border_link_doesnt_crash():
"""Regression test for https://github.com/Textualize/textual/issues/4410"""

class DataTableWithBorderLinkApp(App):
CSS = """
DataTable {
border: solid red;
}
"""
link_clicked = False

def compose(self) -> ComposeResult:
yield DataTable()

def on_mount(self) -> None:
table = self.query_one(DataTable)
table.border_title = "[@click=test_link]Border Link[/]"

def action_test_link(self) -> None:
self.link_clicked = True

app = DataTableWithBorderLinkApp()
async with app.run_test() as pilot:
# Test clicking the link in the border doesn't crash with KeyError: 'row'
await pilot.click(DataTable, offset=(5, 0))
assert app.link_clicked is True
Loading