Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intrinsicContentSize #320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,18 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
XCTAssertEqual(size.height, floatingLabelTextField.titleHeight() + floatingLabelTextField.textHeight())
}

func test_whenIntristicContentSizeInvoked_whenAPlaceHolderIsSet_thenWidthIsNotZero() {
// given
floatingLabelTextField = SkyFloatingLabelTextField() // need to create a new instance with no frame set
floatingLabelTextField.placeholder = "Placeholder"

// when
let width = floatingLabelTextField.intrinsicContentSize.width

// then
XCTAssertGreaterThan(width, 0)
}

// MARK: Error Message Placement
func test_whenSettingErrorMessage_whenErrorMessagePlacementSetToDefault_thenTitleLabelTextIsChanged() {
// given
Expand Down
5 changes: 3 additions & 2 deletions Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,11 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
- returns: the content size to be used for auto layout
*/
override open var intrinsicContentSize: CGSize {
let width = max(super.intrinsicContentSize.width, bounds.size.width)
if errorMessagePlacement == .bottom {
return CGSize(width: bounds.size.width, height: titleHeight() + textHeight() + errorHeight())
return CGSize(width: width, height: titleHeight() + textHeight() + errorHeight())
} else {
return CGSize(width: bounds.size.width, height: titleHeight() + textHeight())
return CGSize(width: width, height: titleHeight() + textHeight())
}
}

Expand Down