@@ -9,7 +9,15 @@ import androidx.compose.foundation.shape.RoundedCornerShape
99import androidx.compose.material3.Text
1010import androidx.compose.runtime.Composable
1111import androidx.compose.ui.Modifier
12+ import androidx.compose.ui.focus.FocusDirection
1213import androidx.compose.ui.graphics.Color
14+ import androidx.compose.ui.input.key.Key
15+ import androidx.compose.ui.input.key.KeyEventType
16+ import androidx.compose.ui.input.key.isShiftPressed
17+ import androidx.compose.ui.input.key.key
18+ import androidx.compose.ui.input.key.onPreviewKeyEvent
19+ import androidx.compose.ui.input.key.type
20+ import androidx.compose.ui.platform.LocalFocusManager
1321import androidx.compose.ui.text.font.FontWeight
1422import androidx.compose.ui.unit.dp
1523import com.composeunstyled.TextField
@@ -34,16 +42,35 @@ fun FieldTextInput(
3442 modifier : Modifier = Modifier ,
3543 onClick : (() -> Unit )? = null,
3644) {
45+ val isMultiline = maxLines > 1
46+ val focusManager = LocalFocusManager .current
47+
3748 TextField (
3849 value = value,
3950 editable = enabled,
4051 onValueChange = {
41- if (enabled) onValueChange(it)
52+ if (! enabled) return @TextField
53+ if (isMultiline && it.count { c -> c == ' \n ' } >= maxLines) return @TextField
54+ onValueChange(it)
4255 },
4356 maxLines = maxLines,
4457 minLines = minLines,
45- singleLine = maxLines == 1 ,
46- modifier = modifier,
58+ singleLine = ! isMultiline,
59+ modifier = modifier.then(
60+ if (isMultiline) {
61+ Modifier .onPreviewKeyEvent { event ->
62+ if (event.key == Key .Tab && event.type == KeyEventType .KeyDown ) {
63+ val direction = if (event.isShiftPressed) FocusDirection .Previous else FocusDirection .Next
64+ focusManager.moveFocus(direction)
65+ true
66+ } else {
67+ false
68+ }
69+ }
70+ } else {
71+ Modifier
72+ }
73+ ),
4774 ) {
4875 if (label != null ) {
4976 RequiredTextLabel (label = label, required = required, fontWeight = FontWeight .SemiBold )
@@ -54,7 +81,7 @@ fun FieldTextInput(
5481 .border(1 .dp, Color (0xFFBDBDBD ), RoundedCornerShape (8 .dp))
5582 .background(if (enabled) Color .White else Color (0xFFF5F5F5 ), RoundedCornerShape (8 .dp))
5683 .padding(horizontal = 16 .dp, vertical = 12 .dp)
57-
84+
5885 TextInput (
5986 inputModifier,
6087 leading = leading,
0 commit comments