Skip to content

Switch should stop the Click event from bubbling #2366

@davep

Description

@davep

At the moment Switch handles Click but then lets it bubble; there's no good reason to do that and it also stops the ability to write something like this:

from textual.app        import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets    import Header, Footer, Label, Switch

class LabeledSwitch( Horizontal ):

    def on_click( self ) -> None:
        self.query_one(Switch).toggle()

class ClickableLabelApp( App[ None ] ):

    def compose( self ) -> ComposeResult:
        yield Header()
        with LabeledSwitch():
            yield Label( "Click me!" )
            yield Switch()
        yield Footer()

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

where the idea is to make a compound widget that lets you click on the Label or the Switch and the Switch will toggle -- only it doesn't work if you click on the Switch because it ends up double-toggling.

Metadata

Metadata

Assignees

Labels

TaskbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions