textual: As of 0.6.0, bindings on (at least) `left`, `right`, `up` and `down` no longer appear to work

With Textual 0.5.0 I had bindings on the arrow keys that worked fine. Having upgraded to 0.6.0 those bindings no longer seem to work. Isolating the issue I can recreate with this code (some other keys thrown in as control tests)

from textual.app import App, ComposeResult
from textual.widgets import TextLog, Header, Footer
from textual.binding import Binding
from textual.events import Key

class Binder( App[ None ] ):

    CSS = """
    TextLog {
        background: #222200;
        color: #BBBB00;
        text-style: bold;
    }
    """

    BINDINGS = [
        Binding( "up",    "log( 'up' )", "Up" ),
        Binding( "down",  "log( 'down' )", "Down" ),
        Binding( "left",  "log( 'left' )", "Left" ),
        Binding( "right", "log( 'right' )", "Right" ),
        Binding( "a", "log( 'a' )", "a" ),
        Binding( "s", "log( 's' )", "s" ),
        Binding( "d", "log( 'd' )", "d" ),
        Binding( "f", "log( 'f' )", "f" ),
        Binding( "left_square_bracket", "log( '[' )", "[" ),
        Binding( "right_square_bracket", "log( ']' )", "]" ),
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield TextLog()
        yield Footer()

    def on_mount( self ) -> None:
        self.query_one( TextLog ).write( "Ready..." )
        self.query_one( TextLog ).write( "Key bindings being looked for:" )
        self.query_one( TextLog ).write( ", ".join(
            [ binding.key for binding in self.BINDINGS ]
        ) )

    def action_log( self, name: str ) -> None:
        self.query_one( TextLog ).write( f"Via binding: {name}" )

    def on_key( self, event: Key ) -> None:
        self.query_one( TextLog ).write( f"Via event: {event!r}" )

if __name__ == "__main__":
    Binder().run()

Running the above, pressing the arrow keys vs some of the other keys…

Screenshot 2022-12-12 at 11 25 12

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (19 by maintainers)

Commits related to this issue

Most upvoted comments

They are the same thing for the base class, and most widgets. But it is possible for something to be scrollable that is not a container. I think the only one we have is ScrollView.