Skip to content

Commit db2892f

Browse files
Merge pull request benjamin-luescher#11 from benjamin-luescher/develop
Fix OutlinedTextField multi-line label.
2 parents 3c0879a + c2bc908 commit db2892f

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencyResolutionManagement {
2323
2424
2. Add the dependency in your build.gradle file.
2525
```kotlin
26-
implementation 'com.github.benjamin-luescher:compose-form:0.2.5'
26+
implementation 'com.github.benjamin-luescher:compose-form:0.2.6'
2727
```
2828

2929
## Easy example

composeform/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ dependencies {
6262

6363
// Reflection
6464
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
65+
debugImplementation 'androidx.compose.ui:ui-tooling:1.5.4'
6566
}
6667

6768
publishing {
6869
publications {
6970
release(MavenPublication) {
7071
groupId = 'com.github.benjamin-luescher'
7172
artifactId = 'compose-form'
72-
version = '0.2.5'
73+
version = '0.2.6'
7374

7475
afterEvaluate {
7576
from components.release

composeform/src/main/java/ch/benlu/composeform/components/TextFieldComponent.kt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
package ch.benlu.composeform.components
22

3-
import android.content.res.Configuration.UI_MODE_NIGHT_NO
43
import androidx.compose.foundation.interaction.MutableInteractionSource
54
import androidx.compose.foundation.layout.Column
65
import androidx.compose.foundation.layout.fillMaxWidth
76
import androidx.compose.foundation.layout.padding
87
import androidx.compose.foundation.text.KeyboardActions
98
import androidx.compose.foundation.text.KeyboardOptions
10-
import androidx.compose.material.*
9+
import androidx.compose.material.Icon
10+
import androidx.compose.material.MaterialTheme
11+
import androidx.compose.material.OutlinedTextField
12+
import androidx.compose.material.Surface
13+
import androidx.compose.material.Text
14+
import androidx.compose.material.TextFieldDefaults
1115
import androidx.compose.material.icons.Icons
1216
import androidx.compose.material.icons.filled.KeyboardArrowDown
13-
import androidx.compose.runtime.*
17+
import androidx.compose.runtime.Composable
18+
import androidx.compose.runtime.remember
1419
import androidx.compose.ui.Modifier
15-
import androidx.compose.ui.draw.drawBehind
1620
import androidx.compose.ui.focus.FocusRequester
1721
import androidx.compose.ui.focus.FocusState
1822
import androidx.compose.ui.focus.focusRequester
1923
import androidx.compose.ui.focus.onFocusChanged
20-
import androidx.compose.ui.geometry.Offset
21-
import androidx.compose.ui.graphics.Color
2224
import androidx.compose.ui.text.TextStyle
2325
import androidx.compose.ui.text.input.ImeAction
2426
import androidx.compose.ui.text.input.KeyboardType
2527
import androidx.compose.ui.text.input.VisualTransformation
28+
import androidx.compose.ui.text.style.TextOverflow
2629
import androidx.compose.ui.tooling.preview.Preview
2730
import androidx.compose.ui.unit.dp
2831

@@ -65,7 +68,13 @@ fun TextFieldComponent(
6568
enabled = isEnabled,
6669
colors = TextFieldDefaults.outlinedTextFieldColors(),
6770
isError = hasError,
68-
label = { Text(label) },
71+
label = {
72+
Text(
73+
maxLines = 1,
74+
overflow = TextOverflow.Ellipsis,
75+
text = label
76+
)
77+
},
6978
readOnly = isReadOnly,
7079
interactionSource = interactionSource ?: remember { MutableInteractionSource() },
7180
visualTransformation = visualTransformation,
@@ -81,7 +90,7 @@ fun TextFieldComponent(
8190
}
8291
}
8392

84-
@Preview(uiMode = UI_MODE_NIGHT_NO)
93+
@Preview
8594
@Composable
8695
fun FormTextFieldPreview() {
8796
Surface {
@@ -104,6 +113,16 @@ fun FormTextFieldPreview() {
104113
hasError = true,
105114
errorText = mutableListOf("Should not be empty.")
106115
)
116+
TextFieldComponent(
117+
modifier = Modifier.padding(bottom = 8.dp),
118+
text = "",
119+
label = "My Label which is very very very long and should be ellipsized",
120+
onChange = {},
121+
keyBoardActions = KeyboardActions.Default,
122+
isEnabled = true,
123+
hasError = true,
124+
errorText = mutableListOf("Should not be empty.")
125+
)
107126
TextFieldComponent(
108127
modifier = Modifier.padding(bottom = 8.dp),
109128
text = "My Picker",

0 commit comments

Comments
 (0)