Issue with TextField label
See original GitHub issueUsing MdcTheme we are experiencing an exception when we define a label on TextField:
java.lang.IllegalArgumentException: Cannot perform operation for Sp and Em
at androidx.compose.ui.unit.TextUnitKt.checkArithmetic-NB67dxo(SourceFile:333)
at androidx.compose.ui.unit.TextUnitKt.lerp-C3pnCVY(SourceFile:364)
at androidx.compose.ui.text.SpanStyleKt.lerpTextUnitInheritable-C3pnCVY(SourceFile:229)
at androidx.compose.ui.text.SpanStyleKt.lerp(SourceFile:280)
at androidx.compose.ui.text.TextStyleKt.lerp(SourceFile:358)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$1$decoratedLabel$1.invoke(SourceFile:109)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$1$decoratedLabel$1.invoke(SourceFile:108)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:121)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:46)
at androidx.compose.material.TextFieldKt.IconsWithTextFieldLayout-SxpAMN0(SourceFile:416)
at androidx.compose.material.TextFieldKt.access$IconsWithTextFieldLayout-SxpAMN0(SourceFile:1)
at androidx.compose.material.TextFieldKt$TextFieldLayout$1.invoke(SourceFile:355)
at androidx.compose.material.TextFieldKt$TextFieldLayout$1.invoke(SourceFile:353)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:130)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:46)
at androidx.compose.foundation.text.CoreTextFieldKt.CoreTextField(SourceFile:447)
at androidx.compose.foundation.text.BasicTextFieldKt.BasicTextField(SourceFile:251)
at androidx.compose.material.TextFieldKt.TextFieldLayout-uBqXD2s(SourceFile:333)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$1.invoke-rAjV9yQ(SourceFile:137)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$1.invoke(SourceFile:104)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:163)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(SourceFile:46)
at androidx.compose.material.TextFieldTransitionScope.Transition(SourceFile:322)
at androidx.compose.material.TextFieldImplKt.TextFieldImpl(SourceFile:102)
at androidx.compose.material.TextFieldKt.TextField(SourceFile:281)
at androidx.compose.material.TextFieldKt.TextField(SourceFile:170)
Switching to MaterialTheme the issue is gone.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
React Material UI textfield label problem - Stack Overflow
I have problem with material ui text field. There is a form with more textinput. When I scroll down the page, the textinputs...
Read more >[TextField] label shows even when other components ... - GitHub
The problem is that the "label" of the TextField appears even when it is supposed to be hidden behind the footer. I initially...
Read more >[BUG] Issue with label text field - Inductive Automation Forum
When entering a value greater than 2^53+1 the number is converted into a string, but is still limited by the precision of the...
Read more >Textfield label overlapping issue - code helper - MDBootstrap
When you click the button below, the same form will be displayed. Note the textfield's label/title - The border will still visible behind...
Read more >React Text Field component - Material UI - MUI
To workaround the issue, you can force the "shrink" state of the label. <TextField InputLabelProps={{ shrink: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem. I’ve filed a bug here for it to be addressed on the Compose Material / UI side: https://issuetracker.google.com/issues/182881244
Thanks, I can reproduce it now and the issue is that this library uses
em
as theTextUnit
when convertingandroid:letterSpacing
into a value forTextStyle
s (in your case 0.04). If noandroid:letterSpacing
is specified then the Compose text default value is0.sp
.I’m currently trying to determine if the fix needs to be in this library, or if the Compose text default value should rather be
0.em
.In the meantime, you can “fix” your issue by:
<item name="android:letterSpacing">0</item>
toTextAppearance.Subtitle1
, orTextAppearance.AppCompat
as the base style, make the parent of each styleTextAppearance.MaterialComponents.Subtitle1
andTextAppearance.MaterialComponents.Caption
respectively (will include defaultandroid:letterSpacing
)