Skip to content
Merged
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
16 changes: 15 additions & 1 deletion components/src/main/kotlin/se/seb/gds/atoms/input/BasicInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.TextFieldLineLimits
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.then
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
Expand Down Expand Up @@ -254,6 +253,21 @@ internal fun getAccessibilityDescription(
descriptionBuilder.append(stringResource(id = R.string.text_field_is_editing))
}

// Announce character count if the text field is valid. If not valid, the error message will
// include the character limit information, so it would be redundant to announce it here as well.
val isCharacterLimitValid =
inputState.characterLimit != null && state.text.length <= inputState.characterLimit.maxCharacters
if (textFieldIsFocused && isCharacterLimitValid) {
descriptionBuilder.append(", ")
descriptionBuilder.append(
stringResource(
id = R.string.text_field_characters_written,
state.text.length,
inputState.characterLimit.maxCharacters,
),
)
}

return descriptionBuilder.toString().replace(" ,", ",").trim()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fun InputContainedCore(
LocalTextSelectionColors provides style.basicInputStyle.textSelectionColors,
) {
BasicTextField(
modifier = Modifier
modifier = modifier
.bringIntoViewRequester(bringIntoViewRequester)
.focusRequester(focusRequester)
.clearAndSetSemantics {
Expand Down
2 changes: 1 addition & 1 deletion components/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="common_action_close">Stäng</string>
<string name="text_field">Textfält</string>
<string name="text_field_error_in_field">Det finns ett fel i Textfält.</string>
<string name="text_field_error_in_field">Det finns ett fel i textfältet.</string>
<string name="text_field_character_limit_error">Du kan skriva högst %d tecken.</string>
<string name="text_field_edit">ändra</string>
<string name="text_field_is_editing">ändrar</string>
Expand Down
Loading