Skip to content

Commit

Permalink
fix(InputField): Avoid TextField auto expands horizontally (#289)
Browse files Browse the repository at this point in the history
* fix(InputField): Avoid TextField auto expands horizontally

* IOS-8333

* Run swiftformat

---------

Co-authored-by: WanaldinoTelefonica <WanaldinoTelefonica@users.noreply.github.com>
  • Loading branch information
WanaldinoTelefonica and WanaldinoTelefonica committed Jul 19, 2023
1 parent ace194c commit c321d88
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public struct InputField: View {
Text(placeholder)
.font(.textPreset1(weight: .regular))
.opacity(0)
.lineLimit(1)

HStack {
leadingText
Expand All @@ -91,6 +92,7 @@ public struct InputField: View {
.offset(x: 0, y: placeholderOffset)
.animation(.misticaTimingCurve, value: placeholderTextColor)
.allowsHitTesting(false)
.lineLimit(1)
}

trailingImage
Expand Down
12 changes: 12 additions & 0 deletions Sources/MisticaSwiftUI/Components/Inputfield/LegacyTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ extension LegacyTextFieldCoordinator {

private class ActionsTextField: UITextField {
var canPerformActions = true

override func contentCompressionResistancePriority(for axis: NSLayoutConstraint.Axis) -> UILayoutPriority {
switch axis {
case .horizontal:
return .defaultLow
case .vertical:
fallthrough
@unknown default:
return super.contentCompressionResistancePriority(for: axis)
}
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
guard canPerformActions else { return false }
return super.canPerformAction(action, withSender: sender)
Expand Down
27 changes: 27 additions & 0 deletions Tests/MisticaSwiftUITests/UI/InputFieldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ final class InputFieldTests: XCTestCase {
as: .image
)
}

func testLongText() {
let input = makeTemplate(style: .text, text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ullamcorper at justo eget porta. Pellentesque sit amet felis vel eros commodo euismod vel quis nisl.")

assertSnapshot(
matching: input,
as: .image
)
}

func testLongPlaceholder() {
let input = makeTemplate(style: .text, placeholder: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ullamcorper at justo eget porta. Pellentesque sit amet felis vel eros commodo euismod vel quis nisl.")

assertSnapshot(
matching: input,
as: .image
)
}

func testLongAssistiveText() {
let input = makeTemplate(style: .text, assistiveText: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ullamcorper at justo eget porta. Pellentesque sit amet felis vel eros commodo euismod vel quis nisl.")

assertSnapshot(
matching: input,
as: .image
)
}
}

private extension InputFieldTests {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c321d88

Please sign in to comment.