Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand Down Expand Up @@ -47,8 +46,7 @@ internal class OudsCheckboxItemTest {
modifier = Modifier.testTag(testTag)
)
}

onNodeWithTag(testTag).assertIsOff()

onNodeWithTag(testTag).performClick()
verify(onCheckedChange).invoke(!checked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand Down Expand Up @@ -47,8 +46,7 @@ internal class OudsRadioButtonItemTest {
modifier = Modifier.testTag(testTag)
)
}

onNodeWithTag(testTag).assertIsNotSelected()

onNodeWithTag(testTag).performClick()
verify(onClick).invoke()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand Down Expand Up @@ -47,8 +46,7 @@ internal class OudsSwitchItemTest {
modifier = Modifier.testTag(testTag)
)
}

onNodeWithTag(testTag).assertIsOff()

onNodeWithTag(testTag).performClick()
verify(onCheckedChange).invoke(!checked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ fun OudsTriStateCheckboxItem(
ToggleableState.Indeterminate -> "Indeterminate"
},
backgroundColor = backgroundColor.value,
modifier = modifier
.then(toggleableModifier)
.semantics(mergeDescendants = true) {},
modifier = modifier.semantics(mergeDescendants = true) {},
contentModifier = toggleableModifier,
handleHighContrastMode = true,
constrainedMaxWidth = constrainedMaxWidth
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ private fun OudsPasswordInput(
emptyText = emptyText,
readOnly = readOnly,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = null,
basicTextField = {
BasicSecureTextField(
modifier = modifier.textInputSemantic(label),
Expand Down Expand Up @@ -316,8 +319,6 @@ private fun OudsPasswordInput(
outlined = outlined,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = null,
constrainedMaxWidth = constrainedMaxWidth
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.substring
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
Expand Down Expand Up @@ -251,32 +252,54 @@ private fun OudsPinCodeInput(
textFieldState = textFieldState,
length = length
) {
BasicSecureTextField(
modifier = modifier
.heightIn(min = OudsTheme.componentsTokens.textInput.sizeMinHeight.dp)
.focusRequester(focusRequester),
state = textFieldState,
keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, keyboardType = KeyboardType.Number),
onKeyboardAction = onKeyboardAction,
inputTransformation = inputTransformation(length),
interactionSource = interactionSource,
decorator = {
OudsPinCodeInputDecorator(
textFieldState = textFieldState,
length = length,
outlined = outlined,
BoxWithConstraints(contentAlignment = Alignment.Center) {
ConstraintLayout {
val (secureTextField, helperTextErrorMessage) = createRefs()
BasicSecureTextField(
modifier = modifier
.heightIn(min = OudsTheme.componentsTokens.textInput.sizeMinHeight.dp)
.constrainAs(secureTextField) {
top.linkTo(parent.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
.focusRequester(focusRequester),
state = textFieldState,
keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, keyboardType = KeyboardType.Number),
onKeyboardAction = onKeyboardAction,
inputTransformation = inputTransformation(length),
interactionSource = interactionSource,
decorator = {
OudsPinCodeInputDecorator(
textFieldState = textFieldState,
length = length,
outlined = outlined,
error = error,
onDigitClick = {
focusRequester.requestFocus()
// If keyboard is dismissed using the Android back key, the keyboard won't reappear when digit is clicked
keyboardController?.show()
},
maxWidth = this@BoxWithConstraints.maxWidth,
interactionSource = interactionSource
)
}
)
OudsTextInputHelperTextErrorMessage(
modifier = Modifier.constrainAs(helperTextErrorMessage) {
top.linkTo(secureTextField.bottom)
bottom.linkTo(parent.bottom)
start.linkTo(secureTextField.start)
end.linkTo(secureTextField.end)
width = Dimension.fillToConstraints
},
enabled = true,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
onDigitClick = {
focusRequester.requestFocus()
// If keyboard is dismissed using the Android back key, the keyboard won't reappear when digit is clicked
keyboardController?.show()
},
interactionSource = interactionSource
annotatedHelperText = annotatedHelperText
)
}
)
}
}
}

Expand Down Expand Up @@ -329,66 +352,39 @@ private fun OudsPinCodeInputDecorator(
length: OudsPinCodeInputLength,
outlined: Boolean,
error: OudsError?,
helperText: String?,
annotatedHelperText: OudsAnnotatedHelperText?,
onDigitClick: (Int) -> Unit,
maxWidth: Dp,
interactionSource: MutableInteractionSource
) {
val interactionState by interactionSource.collectInteractionStateAsState()
val pinCodeInputTokens = OudsTheme.componentsTokens.pinCodeInput
val smallDeviceSpecificRules = smallDeviceSpecificRules(length)
BoxWithConstraints(contentAlignment = Alignment.Center) {
val horizontalSpace = if (smallDeviceSpecificRules) 6.dp else pinCodeInputTokens.spaceColumnGapDigitInput.value
val totalHorizontalSpace = horizontalSpace * (length.value - 1)
val digitWidth = (maxWidth - totalHorizontalSpace) / length.value
ConstraintLayout {
val (row, helperTextErrorMessage) = createRefs()
Row(
modifier = Modifier
.constrainAs(row) {
top.linkTo(parent.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
},
horizontalArrangement = Arrangement.spacedBy(horizontalSpace)
) {
val isNonErrorPreview = LocalInspectionMode.current && error == null
val focusedDigitIndex = (textFieldState.selection.end - 1).coerceIn(0, length.value - 1)
repeat(length.value) { index ->
val digitInputState = when {
(isNonErrorPreview || interactionState == InteractionState.Focused) && index == focusedDigitIndex -> OudsDigitInputState.Focused
interactionState == InteractionState.Hovered -> OudsDigitInputState.Hovered
else -> OudsDigitInputState.Enabled
}
OudsDigitInput(
modifier = Modifier
.width(digitWidth)
.semantics { hideFromAccessibility() },
digit = textFieldState.text.getOrNull(index),
onClick = {
onDigitClick(index)
textFieldState.edit { placeCursorAfterCharAt(index) }
},
state = digitInputState,
outlined = outlined,
error = error != null,
placeholder = error == null,
smallDeviceSpecificRules = smallDeviceSpecificRules
)
}
val horizontalSpace = if (smallDeviceSpecificRules) 6.dp else pinCodeInputTokens.spaceColumnGapDigitInput.value
val totalHorizontalSpace = horizontalSpace * (length.value - 1)
val digitWidth = (maxWidth - totalHorizontalSpace) / length.value
Row(horizontalArrangement = Arrangement.spacedBy(horizontalSpace)) {
val isNonErrorPreview = LocalInspectionMode.current && error == null
val focusedDigitIndex = (textFieldState.selection.end - 1).coerceIn(0, length.value - 1)
repeat(length.value) { index ->
val digitInputState = when {
(isNonErrorPreview || interactionState == InteractionState.Focused) && index == focusedDigitIndex -> OudsDigitInputState.Focused
interactionState == InteractionState.Hovered -> OudsDigitInputState.Hovered
else -> OudsDigitInputState.Enabled
}
OudsTextInputHelperTextErrorMessage(
modifier = Modifier.constrainAs(helperTextErrorMessage) {
top.linkTo(row.bottom)
bottom.linkTo(parent.bottom)
start.linkTo(row.start)
end.linkTo(row.end)
width = Dimension.fillToConstraints
OudsDigitInput(
modifier = Modifier
.width(digitWidth)
.semantics { hideFromAccessibility() },
digit = textFieldState.text.getOrNull(index),
onClick = {
onDigitClick(index)
textFieldState.edit { placeCursorAfterCharAt(index) }
},
enabled = true,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText
state = digitInputState,
outlined = outlined,
error = error != null,
placeholder = error == null,
smallDeviceSpecificRules = smallDeviceSpecificRules
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ fun OudsRadioButtonItem(
checkedContentComponentName = "OudsRadioButtonItem",
checkedContentSelectionStatus = if (selected) "Selected" else "Unselected",
backgroundColor = backgroundColor.value,
modifier = modifier
.then(selectableModifier)
.semantics(mergeDescendants = true) {},
contentModifier = Modifier.border(outlined = outlined, selected = selected, error = error, state = state),
modifier = modifier.semantics(mergeDescendants = true) {},
contentModifier = selectableModifier.border(outlined = outlined, selected = selected, error = error, state = state),
constrainedMaxWidth = constrainedMaxWidth,
handleHighContrastMode = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ fun OudsSwitchItem(
checkedContentComponentName = "OudsSwitchItem",
checkedContentSelectionStatus = if (checked) "Selected" else "Unselected",
backgroundColor = backgroundColor.value,
modifier = modifier
.then(toggleableModifier)
.semantics(mergeDescendants = true) {},
modifier = modifier.semantics(mergeDescendants = true) {},
contentModifier = toggleableModifier,
constrainedMaxWidth = constrainedMaxWidth
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ private fun OudsTextArea(
emptyText = emptyText,
readOnly = readOnly,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
basicTextField = {
BasicTextField(
modifier = modifier.textInputSemantic(label),
Expand All @@ -460,8 +463,6 @@ private fun OudsTextArea(
outlined = outlined,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
constrainedMaxWidth = constrainedMaxWidth,
scrollState = scrollState,
)
Expand Down Expand Up @@ -810,6 +811,9 @@ private fun OudsTextArea(
emptyText = emptyText,
readOnly = readOnly,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
basicTextField = {
BasicTextField(
modifier = modifier.textInputSemantic(label),
Expand Down Expand Up @@ -837,8 +841,6 @@ private fun OudsTextArea(
outlined = outlined,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
constrainedMaxWidth = constrainedMaxWidth
)
}
Expand Down Expand Up @@ -1184,6 +1186,9 @@ private fun OudsTextArea(
emptyText = emptyText,
readOnly = readOnly,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
basicTextField = {
BasicTextField(
modifier = modifier.textInputSemantic(label),
Expand Down Expand Up @@ -1211,8 +1216,6 @@ private fun OudsTextArea(
outlined = outlined,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText,
helperLink = helperLink,
constrainedMaxWidth = constrainedMaxWidth,
)
}
Expand Down Expand Up @@ -1251,8 +1254,6 @@ internal fun OudsTextAreaDecorator(
outlined: Boolean,
error: OudsError?,
helperText: String?,
annotatedHelperText: OudsAnnotatedHelperText?,
helperLink: OudsTextInputHelperLink?,
constrainedMaxWidth: Boolean,
scrollState: ScrollState = rememberScrollState(),
) {
Expand Down Expand Up @@ -1344,18 +1345,6 @@ internal fun OudsTextAreaDecorator(
}
}
}

// Helper text / Error description
OudsTextInputHelperTextErrorMessage(
modifier = Modifier.padding(horizontal = spacePaddingInlineDefault.value),
enabled = state != OudsTextInputState.Disabled,
error = error,
helperText = helperText,
annotatedHelperText = annotatedHelperText
)

// Helper link
helperLink?.Content(extraParameters = OudsTextInputHelperLink.ExtraParameters(state = state))
}
}
}
Expand Down
Loading