Skip to content

Commit

Permalink
make radio button on item change non-nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Sep 14, 2023
1 parent f8b6a22 commit e2391b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ fun RadioButtonInputScreen() {
mutableStateOf<RadioButtonData?>(null)
}

var selectedItemDisabled by remember {
mutableStateOf<RadioButtonData?>(null)
}

var selectedItemHorizontal by remember {
mutableStateOf<RadioButtonData?>(radioButtonDataItemsHorizontal[0])
}
Expand Down Expand Up @@ -88,6 +92,9 @@ fun RadioButtonInputScreen() {
title = "Label",
radioButtonData = radioButtonDataItemsDisabled,
state = InputShellState.DISABLED,
onItemChange = {
selectedItemDisabled = it
},
)
Spacer(Modifier.size(Spacing.Spacing18))
SubTitle("Horizontal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fun RadioButtonBlock(
orientation: Orientation,
content: List<RadioButtonData>,
itemSelected: RadioButtonData?,
onItemChange: ((RadioButtonData) -> Unit)? = null,
onItemChange: (RadioButtonData) -> Unit,
) {
if (orientation == Orientation.HORIZONTAL) {
FlowRowComponentsContainer(
Expand All @@ -124,7 +124,7 @@ fun RadioButtonBlock(
radioButtonData.textInput,
),
) {
onItemChange?.invoke(radioButtonData)
onItemChange.invoke(radioButtonData)
}
}
},
Expand All @@ -143,7 +143,7 @@ fun RadioButtonBlock(
radioButtonData.textInput,
),
) {
onItemChange?.invoke(radioButtonData)
onItemChange.invoke(radioButtonData)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun RadioButtonInput(
legendData: LegendData? = null,
isRequired: Boolean = false,
itemSelected: RadioButtonData? = null,
onItemChange: ((RadioButtonData?) -> Unit)? = null,
onItemChange: (RadioButtonData?) -> Unit,
) {
InputShell(
modifier = modifier.testTag("RADIO_BUTTON_INPUT"),
Expand Down Expand Up @@ -84,7 +84,7 @@ fun RadioButtonInput(
)
},
onClick = {
onItemChange?.invoke(null)
onItemChange.invoke(null)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ class RadioButtonInputTest {
RadioButtonData("1", selected = false, enabled = true, textInput = "Option 2"),
RadioButtonData("2", selected = false, enabled = true, textInput = "Option 3"),
)
val selectedItem by remember {
var selectedItem by remember {
mutableStateOf<RadioButtonData?>(radioButtonData[0])
}
RadioButtonInput(
title = "Label",
radioButtonData = radioButtonData,
itemSelected = selectedItem,
modifier = Modifier.testTag("RADIO_BUTTON_INPUT"),
onItemChange = {
selectedItem = it
},
)
}
rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
Expand Down Expand Up @@ -105,14 +108,17 @@ class RadioButtonInputTest {
RadioButtonData("1", selected = false, enabled = true, textInput = "Option 2"),
RadioButtonData("2", selected = false, enabled = true, textInput = "Option 3"),
)
val selectedItem by remember {
var selectedItem by remember {
mutableStateOf<RadioButtonData?>(radioButtonData[0])
}
RadioButtonInput(
title = "Label",
radioButtonData = radioButtonData,
modifier = Modifier.testTag("RADIO_BUTTON_INPUT"),
itemSelected = selectedItem,
onItemChange = {
selectedItem = it
},
)
}
rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
Expand All @@ -127,11 +133,16 @@ class RadioButtonInputTest {
RadioButtonData("1", selected = false, enabled = true, textInput = "Option 2"),
RadioButtonData("2", selected = false, enabled = true, textInput = "Option 3"),
)

var selectedItem by remember {
mutableStateOf<RadioButtonData?>(null)
}
RadioButtonInput(
title = "Label",
radioButtonData = radioButtonData,
modifier = Modifier.testTag("RADIO_BUTTON_INPUT"),
onItemChange = {
selectedItem = it
},
)
}
rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
Expand All @@ -146,7 +157,7 @@ class RadioButtonInputTest {
RadioButtonData("1", selected = false, enabled = true, textInput = "Option 2"),
RadioButtonData("2", selected = false, enabled = true, textInput = "Option 3"),
)
val selectedItem by remember {
var selectedItem by remember {
mutableStateOf<RadioButtonData?>(radioButtonData[0])
}
RadioButtonInput(
Expand All @@ -155,6 +166,9 @@ class RadioButtonInputTest {
state = InputShellState.DISABLED,
itemSelected = selectedItem,
modifier = Modifier.testTag("RADIO_BUTTON_INPUT"),
onItemChange = {
selectedItem = it
},
)
}
rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
Expand Down Expand Up @@ -201,6 +215,7 @@ class RadioButtonInputTest {
title = "Label",
radioButtonData = radioButtonData,
legendData = LegendData(SurfaceColor.CustomGreen, "Legend"),
onItemChange = {},
)
}

Expand All @@ -221,6 +236,7 @@ class RadioButtonInputTest {
title = "Label",
radioButtonData = radioButtonData,
supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)),
onItemChange = {},
)
}
rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
Expand Down

0 comments on commit e2391b5

Please sign in to comment.