Skip to content

Conversation

@nikhil2004-blip
Copy link

Description

Adds a clear() method to RadioSet that deselects all radio buttons, returning the set to its initial unset state.

Changes

  • Implements RadioSet.clear() to deselect all buttons
  • Returns RadioSet to initial unset state
  • Updated RadioSet._on_radio_set_changed() to handle cleared state (index=-1)
  • Updated RadioSet.Changed.__init__() to accept pressed: RadioButton | None
  • Useful for surveys/questionnaires where no response is valid
  • Fixes Adding an option to clear the RadioSet #6198

Motivation

As discussed in #6197, this enables use cases where an unset RadioSet is needed, such as survey interfaces where "no response" is a valid state, without requiring a "Skip" button workaround.

Usage Example

from textual.widgets import RadioSet

radio_set = RadioSet("Yes", "No")
# User selects something...
radio_set.clear()  # Now nothing is selected

Testing

Added comprehensive tests in tests/test_radio_set_clear.py covering:

  • Basic clear functionality
  • Clearing empty RadioSet
  • Multiple clears (idempotent)
  • Selecting after clearing

Please review the following checklist.

  • [✅ ] Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

after review i can update documentation and CHANGELOG.md

- Implements RadioSet.clear() to deselect all buttons
- Returns RadioSet to initial unset state
- Useful for surveys/questionnaires where no response is valid
- Fixes Textualize#6198
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 this pull request may close these issues.

Adding an option to clear the RadioSet

1 participant