@@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.padding
2323import androidx.compose.foundation.shape.RoundedCornerShape
2424import androidx.compose.foundation.text.KeyboardOptions
2525import androidx.compose.material3.OutlinedTextField
26+ import androidx.compose.material3.OutlinedTextFieldDefaults
2627import androidx.compose.material3.Text
2728import androidx.compose.material3.TextFieldColors
2829import androidx.compose.runtime.Composable
@@ -41,6 +42,7 @@ import uk.gov.hmrc.components.compose.atom.text.ErrorText
4142import uk.gov.hmrc.components.compose.molecule.input.CommonInputView.CHAR_COUNT_WIDTH
4243import uk.gov.hmrc.components.compose.molecule.input.CommonInputView.ERROR_TEXT_WITH_CHAR_COUNT_WIDTH
4344import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme
45+ import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors
4446import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.typography
4547
4648@Suppress(" LongParameterList" )
@@ -59,11 +61,19 @@ internal fun TextField(
5961 colors : TextFieldColors ,
6062 trailingIcon : @Composable() (() -> Unit )? = null,
6163 textStyle : TextStyle = typography.body,
62- interactionSource : MutableInteractionSource = remember { MutableInteractionSource () }
64+ interactionSource : MutableInteractionSource = remember { MutableInteractionSource () },
65+ isCustomErrorInputHandle : Boolean
6366) {
67+ var customIsError = isError
68+ val customColors = if (isCustomErrorInputHandle && isError) {
69+ customIsError = false
70+ customTextInputViewColors(colors, isError)
71+ } else {
72+ colors
73+ }
6474 OutlinedTextField (
6575 modifier = modifier.fillMaxWidth(),
66- isError = isError ,
76+ isError = customIsError ,
6777 value = value,
6878 onValueChange = onInputValueChange,
6979 prefix = prefix,
@@ -73,7 +83,7 @@ internal fun TextField(
7383 singleLine = singleLine,
7484 keyboardOptions = keyboardOptions,
7585 textStyle = textStyle,
76- colors = colors ,
86+ colors = customColors ,
7787 shape = RoundedCornerShape (0 ),
7888 visualTransformation = visualTransformation,
7989 interactionSource = interactionSource,
@@ -157,6 +167,36 @@ internal fun errorTextCounterCombo(
157167 }
158168}
159169
170+ @Composable
171+ internal fun customTextInputViewColors (textFieldColors : TextFieldColors , isError : Boolean ): TextFieldColors {
172+ return OutlinedTextFieldDefaults .colors(
173+ focusedTextColor = textFieldColors.focusedTextColor,
174+ unfocusedTextColor = textFieldColors.unfocusedTextColor,
175+ errorTextColor = textFieldColors.errorTextColor,
176+ errorLeadingIconColor = textFieldColors.errorLeadingIconColor,
177+ focusedTrailingIconColor = textFieldColors.focusedTrailingIconColor,
178+ unfocusedTrailingIconColor = textFieldColors.unfocusedTrailingIconColor,
179+ errorTrailingIconColor = textFieldColors.errorTrailingIconColor,
180+ focusedLabelColor = textFieldColors.focusedLabelColor,
181+ unfocusedLabelColor = textFieldColors.unfocusedLabelColor,
182+ errorLabelColor = textFieldColors.errorLabelColor,
183+ focusedBorderColor = if (isError) {
184+ colors.hmrcBlack
185+ } else {
186+ colors.hmrcBlue
187+ },
188+ errorBorderColor = colors.hmrcBlack,
189+ unfocusedBorderColor = colors.hmrcBlack,
190+ focusedPlaceholderColor = textFieldColors.focusedPlaceholderColor,
191+ unfocusedPlaceholderColor = textFieldColors.unfocusedPlaceholderColor,
192+ errorPlaceholderColor = textFieldColors.errorPlaceholderColor,
193+ errorSupportingTextColor = textFieldColors.errorSupportingTextColor,
194+ focusedSupportingTextColor = textFieldColors.focusedSupportingTextColor,
195+ cursorColor = textFieldColors.cursorColor,
196+ errorCursorColor = textFieldColors.errorCursorColor,
197+ )
198+ }
199+
160200object CommonInputView {
161201 const val ERROR_TEXT_WITH_CHAR_COUNT_WIDTH = 0.8f
162202 const val CHAR_COUNT_WIDTH = 0.95f
0 commit comments