Skip to content

Commit 9ac5c82

Browse files
authored
HMA-9778-textview-accessibility-invalid-input (#207)
1 parent 8de4c40 commit 9ac5c82

File tree

90 files changed

+53
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+53
-7
lines changed

components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/input/CommonInputView.kt

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.padding
2323
import androidx.compose.foundation.shape.RoundedCornerShape
2424
import androidx.compose.foundation.text.KeyboardOptions
2525
import androidx.compose.material3.OutlinedTextField
26+
import androidx.compose.material3.OutlinedTextFieldDefaults
2627
import androidx.compose.material3.Text
2728
import androidx.compose.material3.TextFieldColors
2829
import androidx.compose.runtime.Composable
@@ -41,6 +42,7 @@ import uk.gov.hmrc.components.compose.atom.text.ErrorText
4142
import uk.gov.hmrc.components.compose.molecule.input.CommonInputView.CHAR_COUNT_WIDTH
4243
import uk.gov.hmrc.components.compose.molecule.input.CommonInputView.ERROR_TEXT_WITH_CHAR_COUNT_WIDTH
4344
import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme
45+
import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors
4446
import 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+
160200
object CommonInputView {
161201
const val ERROR_TEXT_WITH_CHAR_COUNT_WIDTH = 0.8f
162202
const val CHAR_COUNT_WIDTH = 0.95f

components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/input/PasswordInputView.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fun PasswordInputView(
8181
numericOnly: Boolean = true,
8282
maxChars: Int? = null,
8383
requiredSequencesSpacing: Boolean = true,
84+
isCustomErrorInputHandle: Boolean = false
8485
) {
8586
// pattern matches a non decimal number
8687
val nonDecimalPattern = remember { Regex("^([0-9]*)$") }
@@ -110,7 +111,8 @@ fun PasswordInputView(
110111
passwordTrailingButton = passwordTrailingButton,
111112
maxChars = maxChars,
112113
numericOnly = numericOnly,
113-
requiredSequencesSpacing = requiredSequencesSpacing
114+
requiredSequencesSpacing = requiredSequencesSpacing,
115+
isCustomErrorInputHandle = isCustomErrorInputHandle
114116
)
115117
}
116118

@@ -169,6 +171,7 @@ private fun PasswordTextInputView(
169171
maxChars: Int? = null,
170172
requiredSequencesSpacing: Boolean = true,
171173
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
174+
isCustomErrorInputHandle: Boolean
172175
) {
173176
var hideButtonShown: Boolean by rememberSaveable { mutableStateOf(false) }
174177

@@ -277,7 +280,8 @@ private fun PasswordTextInputView(
277280
unfocusedBorderColor = HmrcTheme.colors.hmrcTransparent,
278281
focusedBorderColor = HmrcTheme.colors.hmrcTransparent
279282
),
280-
interactionSource = interactionSource
283+
interactionSource = interactionSource,
284+
isCustomErrorInputHandle = isCustomErrorInputHandle
281285
)
282286
}
283287

components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/input/TextInputView.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ object TextInputView {
5555
maxChars: Int? = null,
5656
singleLine: Boolean = false,
5757
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
58-
requiredSequencesSpacing: Boolean = false
58+
requiredSequencesSpacing: Boolean = false,
59+
isCustomErrorInputHandle: Boolean = false
5960
) {
6061
var localValue: String by rememberSaveable { mutableStateOf(value.orEmpty()) }
6162
localValue = value.orEmpty()
@@ -109,7 +110,8 @@ object TextInputView {
109110
trailingIcon = clearTrailingIcon,
110111
colors = HmrcTheme.textFieldColors,
111112
textStyle =
112-
if (requiredSequencesSpacing) { HmrcTheme.typography.sequencesBody } else { HmrcTheme.typography.body }
113+
if (requiredSequencesSpacing) { HmrcTheme.typography.sequencesBody } else { HmrcTheme.typography.body },
114+
isCustomErrorInputHandle = isCustomErrorInputHandle
113115
)
114116
}
115117
}
-7.9 KB
-8.11 KB
-2.59 KB
-11.7 KB
-11.5 KB
-21.1 KB
-7.7 KB

0 commit comments

Comments
 (0)