Skip to content

Commit

Permalink
Merge branch 'main' into ANDROAPP-5572-mobile-ui-Create-InputOrgUnit-…
Browse files Browse the repository at this point in the history
…component
  • Loading branch information
siddh1004 authored Oct 6, 2023
2 parents e013521 + 817c6a9 commit de144bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations
Expand Down Expand Up @@ -60,14 +62,17 @@ internal fun BasicTextInput(

var deleteButtonIsVisible by remember { mutableStateOf(!inputText.isNullOrEmpty() && state != InputShellState.DISABLED) }
val focusManager = LocalFocusManager.current
val focusRequester = remember { FocusRequester() }

var deleteButton:
@Composable()
(() -> Unit)? = null
if (deleteButtonIsVisible) {
deleteButton = {
IconButton(
modifier = Modifier.testTag("INPUT_" + testTag + "_RESET_BUTTON").padding(Spacing.Spacing0),
modifier = Modifier
.testTag("INPUT_" + testTag + "_RESET_BUTTON")
.padding(Spacing.Spacing0),
icon = {
Icon(
imageVector = Icons.Outlined.Cancel,
Expand All @@ -77,14 +82,16 @@ internal fun BasicTextInput(
onClick = {
onValueChanged?.invoke("")
deleteButtonIsVisible = false
onFocusChanged?.invoke(true)
focusRequester.requestFocus()
},
enabled = state != InputShellState.DISABLED,
)
}
}
InputShell(
modifier = modifier.testTag("INPUT_$testTag"),
modifier = modifier
.testTag("INPUT_$testTag")
.focusRequester(focusRequester),
isRequiredField = isRequiredField,
title = title,
primaryButton = deleteButton,
Expand All @@ -96,8 +103,7 @@ internal fun BasicTextInput(
}
},
supportingText = {
supportingText?.forEach {
label ->
supportingText?.forEach { label ->
SupportingText(
label.text,
label.state,
Expand All @@ -115,7 +121,9 @@ internal fun BasicTextInput(
onInputChanged = {
if (allowedCharacters != null) {
if (allowedCharacters == RegExValidations.SINGLE_LETTER.regex) {
if (it.uppercase(Locale.getDefault()).matches(allowedCharacters) || it.isEmpty()) {
if (it.uppercase(Locale.getDefault())
.matches(allowedCharacters) || it.isEmpty()
) {
onValueChanged?.invoke(it.uppercase(Locale.getDefault()))
deleteButtonIsVisible = it.isNotEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun InputShell(
modifier: Modifier = Modifier,
) {
Column(modifier = modifier.fillMaxWidth().clip(shape = RoundedCornerShape(Radius.XS, Radius.XS))) {
var indicatorColor by remember { mutableStateOf(InputShellState.UNFOCUSED.color) }
var indicatorColor by remember(state) { mutableStateOf(state.color) }
var indicatorThickness by remember { mutableStateOf(Border.Thin) }
val backgroundColor = if (state != InputShellState.DISABLED) SurfaceColor.Surface else SurfaceColor.DisabledSurface
InputShellRow(
Expand Down

0 comments on commit de144bd

Please sign in to comment.