Skip to content

Commit 8c7ef09

Browse files
committed
library: Opt MiuixTextField when no label text
1 parent 0779ef5 commit 8c7ef09

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

composeApp/src/commonMain/kotlin/component/OtherComponent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fun OtherComponent(padding: PaddingValues) {
9696
MiuixTextField(
9797
value = text1,
9898
onValueChange = { text1 = it },
99-
label = "Text Field",
99+
insideMargin = DpSize(14.dp, 14.dp),
100100
modifier = Modifier.padding(horizontal = 24.dp, vertical = 20.dp),
101101
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
102102
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
@@ -109,7 +109,7 @@ fun OtherComponent(padding: PaddingValues) {
109109
label = "Text Field",
110110
modifier = Modifier.padding(horizontal = 24.dp),
111111
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
112-
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
112+
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
113113
)
114114

115115
MiuixSlider(

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/MiuixSearchBar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ fun MiuixInputField(
180180
modifier = Modifier
181181
.weight(1f)
182182
.then(paddingModifier),
183+
contentAlignment = Alignment.CenterStart
183184
) {
184-
185185
MiuixText(
186-
text = if (!focused) label else "",
186+
text = if (!(query.isNotEmpty() || expanded)) label else "",
187187
color = MiuixTheme.colorScheme.textFieldSub
188188
)
189189

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/MiuixTextField.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ fun MiuixTextField(
9999
val innerTextOffsetY by animateDpAsState(if (value.text.isNotEmpty()) (insideMargin.height / 2) else 0.dp)
100100
val labelFontSize by animateDpAsState(if (value.text.isNotEmpty()) 10.dp else 16.dp)
101101
val border = Modifier.border(borderWidth, borderColor, SquircleShape(cornerRadius))
102-
val labelOffset = Modifier.offset(y = labelOffsetY)
103-
val innerTextOffset = Modifier.offset(y = innerTextOffsetY)
102+
val labelOffset = if (label != "") Modifier.offset(y = labelOffsetY) else Modifier
103+
val innerTextOffset = if (label != "") Modifier.offset(y = innerTextOffsetY) else Modifier
104104

105105
BasicTextField(
106106
value = value,
@@ -195,7 +195,7 @@ fun MiuixTextField(
195195
value: String,
196196
onValueChange: (String) -> Unit,
197197
modifier: Modifier = Modifier,
198-
insideMargin: DpSize = DpSize(18.dp, 18.dp),
198+
insideMargin: DpSize = DpSize(16.dp, 16.dp),
199199
backgroundColor: Color = MiuixTheme.colorScheme.textFieldBg,
200200
cornerRadius: Dp = 18.dp,
201201
label: String = "",
@@ -229,8 +229,8 @@ fun MiuixTextField(
229229
val innerTextOffsetY by animateDpAsState(if (value.isNotEmpty()) (insideMargin.height / 2) else 0.dp)
230230
val labelFontSize by animateDpAsState(if (value.isNotEmpty()) 10.dp else 16.dp)
231231
val border = Modifier.border(borderWidth, borderColor, SquircleShape(cornerRadius))
232-
val labelOffset = Modifier.offset(y = labelOffsetY)
233-
val innerTextOffset = Modifier.offset(y = innerTextOffsetY)
232+
val labelOffset = if (label != "") Modifier.offset(y = labelOffsetY) else Modifier
233+
val innerTextOffset = if (label != "") Modifier.offset(y = innerTextOffsetY) else Modifier
234234

235235
BasicTextField(
236236
value = value,

0 commit comments

Comments
 (0)