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

Clicking priority binding in Footer doesn't call the correct action #4794

Closed
TomJGooding opened this issue Jul 23, 2024 · 2 comments · Fixed by #4798
Closed

Clicking priority binding in Footer doesn't call the correct action #4794

TomJGooding opened this issue Jul 23, 2024 · 2 comments · Fixed by #4798

Comments

@TomJGooding
Copy link
Contributor

Originally reported in PR #4793 - please correct me @bjesus if I've misunderstood the issue.

The example below has a priority binding in the App, which should be checked prior to the binding to the same key in the TestWidget.

When the TestWidget is focused:

  • Pressing the b key calls the correct action from the app ✅
  • Clicking the binding in the Footer instead calls the overridden action in the widget ❌

After moving focus by clicking the button (or pressing Tab):

  • Pressing the b key calls the correct action from the app ✅
  • Clicking the binding in the Footer now seems to do nothing ❌
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widget import Widget
from textual.widgets import Button, Footer


class TestWidget(Widget, can_focus=True):
    BINDINGS = [
        Binding("b", "widget_binding", "Overridden Binding"),
    ]

    DEFAULT_CSS = """
    TestWidget {
        border: tall $background;
        width: 50%;
        height: 50%;
        content-align: center middle;

        &:focus {
            border: tall $accent;
        }
    }
    """

    def action_widget_binding(self) -> None:
        self.app.notify("Overridden Binding", severity="error")


class PriorityBindingApp(App):
    BINDINGS = [
        Binding("b", "app_binding", "Priority Binding", priority=True),
    ]

    CSS = """
    Screen {
        align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
        yield TestWidget()
        yield Button("Move Focus")
        yield Footer()

    def action_app_binding(self) -> None:
        self.app.notify("Priority Binding")


if __name__ == "__main__":
    app = PriorityBindingApp()
    app.run()
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant