-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
I feel the way that an action is found for a @click link is unintuitive. Consider this code:
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.screen import Screen
from textual.widgets import Label
class ClickLabel(Label):
def action_click(self) -> None:
self.notify("ClickLabel.action_click reporting in!")
class Clicker(Vertical):
def compose(self) -> ComposeResult:
yield Label("1: [@click=app.click]Click on this for an app action to fire[/]")
yield Label("2: [@click=screen.click]Click on this for a screen action to fire[/]")
yield Label("3: [@click=click]Click on this for this container's action to fire[/]")
yield ClickLabel("4: [@click=click]Click on this for the custom widget's action to fire[/]")
def action_click(self) -> None:
self.notify("Clicker.action_click reporting in!")
class MainScreen(Screen):
def compose(self) -> ComposeResult:
yield Clicker()
def action_click(self) -> None:
self.notify("Screen.action_click reporting in!")
class ClickBaitApp(App[None]):
def on_mount(self) -> None:
self.push_screen(MainScreen())
def action_click(self) -> None:
self.notify("App.action_click reporting in!")
if __name__ == "__main__":
ClickBaitApp().run()Here's what happens when you click on each of those links:
- The App-level action is fired. This is expected.
- The screen-level action is fired. This is expected.
- The App-level action is fired; this is (I think) unexpected.
- The widget-level action is fired; this is expected.
I feel the way that situation 3 is handled is unintuitive. Surely it would make more sense to have actions that handle clicks looked for going up the DOM? Or if not that, how would we at least introduce a parent namespace too? I feel it's obvious an intuitive that someone would want to compose a collection of widgets into a container and have @click links in the child widgets handled by an action on the container.
valentingregoire