Skip to content

Commit

Permalink
Fix trailingLabel spacing when M3CTextField is used in a UICollecti…
Browse files Browse the repository at this point in the history
…onViewCell.

PiperOrigin-RevId: 575936639
  • Loading branch information
CGRect authored and material-automation committed Oct 23, 2023
1 parent 2b78a3f commit eb9145f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/M3CTextField/src/M3CTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ public final class M3CTextField: UIView, M3CTextInput {
public func setTrailingLabelColor(_ color: UIColor?, for state: UIControl.State) {
trailingLabelColors[state] = color
}

override public func layoutSubviews() {
super.layoutSubviews()

// Hide or show `trailingLabel`, depending on whether or not it is empty.
// This is to fix an issue in RTL, where an empty trailing label affects the position of the
// leading label when M3CTextField is placed inside of a UICollectionViewCell.
trailingLabel.isHidden = (trailingLabel.text ?? "").isEmpty
}
}

// MARK: M3CTextField Custom Clear Button
Expand Down

0 comments on commit eb9145f

Please sign in to comment.