Search code examples
iosswiftios13material-components

MDCTextField rightView property broken on iOS 13


I can't use the rightView property with MDCTextField anymore on iOS 13. Am I the only one having an issue with this?

The right view width cover the whole text field: preventing the user interaction and hiding the textView content.

No problem when I switch from MDCTextField to UITextField.


Solution

  • Add width constraint to the rightView/leftView.

    Don't forget to set translatesAutoresizingMaskIntoConstraints = false

    rightView.translatesAutoresizingMaskIntoConstraints = false
    rightView.widthAnchor.constraint(equalToConstant: <#NeededWidth#>).isActive = true
    // This is enough to make it act like before but you can set other missing constraints like height to suppress layout warnings and prevent further issues.
    // rightView.widthAnchor.constraint(equalToConstant: <#HeightOfTheTextField#>).isActive = true
    

    You may notice some autolayout warnings in the consule because you didn't set the missing constraint for the rightView/leftView. So add missing constraints or simply ignore those.

    And note that if the rightView/leftView is some kind of StackView, try to putting it inside a view and then add this view instead.