question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with TextField label

See original GitHub issue

Using 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ricknoutcommented, Mar 16, 2021

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

1reaction
ricknoutcommented, Mar 15, 2021

Thanks, I can reproduce it now and the issue is that this library uses em as the TextUnit when converting android:letterSpacing into a value for TextStyles (in your case 0.04). If no android:letterSpacing is specified then the Compose text default value is 0.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:

  • Adding <item name="android:letterSpacing">0</item> to TextAppearance.Subtitle1, or
  • Instead of having TextAppearance.AppCompat as the base style, make the parent of each style TextAppearance.MaterialComponents.Subtitle1 and TextAppearance.MaterialComponents.Caption respectively (will include default android:letterSpacing)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found