-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
mandatory
argument for ToggleButtons (#277)
* mandatory attribute and typing for ToggleButtons * Implementing suggestions from code review Co-authored-by: Maarten Breddels <[email protected]> Implementing rest of the changes from code review Further code review Co-authored-by: Maarten Breddels <[email protected]> Implementing suggestions from code review
- Loading branch information
1 parent
348ab5a
commit 1235904
Showing
2 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Optional | ||
|
||
import solara | ||
|
||
|
||
def test_toggle_buttons_single(): | ||
value: solara.Reactive[Optional[str]] = solara.reactive(None) | ||
|
||
@solara.component | ||
def Test(): | ||
with solara.ToggleButtonsSingle("noot", on_value=value.set): | ||
solara.Button("Aap", value="aap") | ||
solara.Button("Noot", value="noot") | ||
solara.Button("Mies", value="mies") | ||
|
||
group, rc = solara.render_fixed(Test()) | ||
assert group.v_model == 1 | ||
group.v_model = 2 | ||
assert value.value == "mies" | ||
|
||
|
||
def test_toggle_buttons_multiple(): | ||
value: solara.Reactive[Optional[str]] = solara.reactive(None) | ||
|
||
@solara.component | ||
def Test(): | ||
with solara.ToggleButtonsMultiple(["noot"], on_value=value.set): | ||
solara.Button("Aap", value="aap") | ||
solara.Button("Noot", value="noot") | ||
solara.Button("Mies", value="mies") | ||
|
||
group, rc = solara.render_fixed(Test()) | ||
assert group.v_model == [1] | ||
group.v_model = [0, 2] | ||
assert value.value is not None | ||
assert value.value == ["aap", "mies"] |