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

How to prevent RadioButton (that are dynamically mounted to RadioSet) from expansion animation on mouse click? #5214

Open
learnbyexample opened this issue Nov 6, 2024 Discussed in #5213 · 4 comments

Comments

@learnbyexample
Copy link
Contributor

Discussed in #5213

Originally posted by learnbyexample November 6, 2024
Here's a sample program:

from textual.app import App
from textual.widgets import RadioButton, RadioSet

class TestApp(App):

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

    def __init__(self):
        super().__init__()
        self.rset = RadioSet()    
    
    def compose(self):
        yield RadioSet('apple', 'banana', 'cherry')
        yield self.rset

    def on_mount(self):
        self.dark = False
        rb1 = RadioButton('true')
        self.rset.mount(rb1)
        rb2 = RadioButton('false')
        self.rset.mount(rb2)

if __name__ == "__main__":
    app = TestApp()
    app.run()

Here's a sample video when the above program is run:

rset.mp4

Is there a way to prevent the RadioButtons from animating in the second case (the RadioSet with true/false choices)?

For my actual use case, I need to dynamically add/remove existing RadioButtons from a RadioSet (the number of RadioButtons vary, need to show a pre-selected choice if applicable, change styling, etc - which is why I'm using mount).

Copy link

github-actions bot commented Nov 6, 2024

We found the following entries 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

@learnbyexample
Copy link
Contributor Author

I found that using border: none; prevents the expansion animation. I'd now actually prefer if nothing is changed to the current behavior of using mount compared to the normal behavior of RadioSet.

@Zaloog
Copy link
Contributor

Zaloog commented Nov 14, 2024

Hi @learnbyexample ,
In the source for Radioset you have some processing for the buttons here.
The flickering has to do with the fact that the RadioButtons can have focus.
If initialized with the buttons directly this doesnt happen, i.e. btn.can_focus = False is set.

I just tested it with your example, If you adjust that, the flickering doesnt occur:

        self.dark = False
        rb1 = RadioButton('true')
        rb1.can_focus = False
        self.rset.mount(rb1)
        rb2 = RadioButton('false')
        rb2.can_focus = False
        self.rset.mount(rb2)

have a great day :)

@learnbyexample
Copy link
Contributor Author

@Zaloog thanks!

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

No branches or pull requests

2 participants