Skip to content

fix: theme support for text fields input and place holder values #100

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

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
22 changes: 20 additions & 2 deletions Sources/Authenticator/Views/Primitives/PasswordField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct PasswordField: View {
}
}
.textFieldStyle(.plain)
.foregroundColor(foregroundColor)
.frame(height: Platform.isMacOS ? 20 : 25)
.padding([.top, .bottom, .leading], theme.components.field.padding)
#if os(iOS)
Expand All @@ -86,10 +87,10 @@ struct PasswordField: View {

@ViewBuilder private func createInput() -> some View {
if isShowingPassword {
SwiftUI.TextField(placeholder, text: $text)
SwiftUI.TextField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
.focused($focusedField, equals: .plain)
} else {
SwiftUI.SecureField(placeholder, text: $text)
SwiftUI.SecureField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
.focused($focusedField, equals: .secure)
}
}
Expand All @@ -98,6 +99,23 @@ struct PasswordField: View {
return focusedField != nil
}

private func createPlaceHolderView(label: String) -> SwiftUI.Text {
let textView = SwiftUI.Text(label)
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
.font(theme.fonts.body)
textView.accessibilityHidden(true)
return textView
}

private var foregroundColor: Color {
switch validator.state {
case .normal:
return theme.colors.foreground.secondary
case .error:
return theme.colors.foreground.error
}
}

private var showPasswordButtonColor: Color {
switch validator.state {
case .normal:
Expand Down
11 changes: 10 additions & 1 deletion Sources/Authenticator/Views/Primitives/PhoneNumberField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct PhoneNumberField: View {
.frame(width: 1)
.overlay(theme.colors.border.primary)

SwiftUI.TextField(placeholder, text: $phoneNumber)
SwiftUI.TextField("", text: $phoneNumber, prompt: createPlaceHolderView(label: placeholder))
.disableAutocorrection(true)
.focused($focusedField, equals: .phoneNumber)
.onChange(of: phoneNumber) { newValue in
Expand Down Expand Up @@ -100,6 +100,7 @@ struct PhoneNumberField: View {
"authenticator.field.phoneNumber.label".localized()
))
.textFieldStyle(.plain)
.foregroundColor(foregroundColor)
.frame(height: Platform.isMacOS ? 20 : 25)
.padding([.top, .bottom, .leading], theme.components.field.padding)
#if os(iOS)
Expand All @@ -124,6 +125,14 @@ struct PhoneNumberField: View {
}
}

private func createPlaceHolderView(label: String) -> SwiftUI.Text {
let textView = SwiftUI.Text(label)
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
.font(theme.fonts.body)
textView.accessibilityHidden(true)
return textView
}

private var foregroundColor: Color {
switch validator.state {
case .normal:
Expand Down
20 changes: 19 additions & 1 deletion Sources/Authenticator/Views/Primitives/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct TextField: View {
isFocused: isFocused
) {
HStack {
SwiftUI.TextField(placeholder, text: $text)
SwiftUI.TextField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
.disableAutocorrection(true)
.focused($isFocused)
.onChange(of: text) { text in
Expand All @@ -65,6 +65,7 @@ struct TextField: View {
}
}
.textFieldStyle(.plain)
.foregroundColor(foregroundColor)
.frame(height: Platform.isMacOS ? 20 : 25)
.padding([.top, .bottom, .leading], theme.components.field.padding)
#if os(iOS)
Expand All @@ -82,6 +83,23 @@ struct TextField: View {
}
}

private func createPlaceHolderView(label: String) -> SwiftUI.Text {
let textView = SwiftUI.Text(label)
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
.font(theme.fonts.body)
textView.accessibilityHidden(true)
return textView
}

private var foregroundColor: Color {
switch validator.state {
case .normal:
return theme.colors.foreground.secondary
case .error:
return theme.colors.foreground.error
}
}

private var clearButtonColor: Color {
switch validator.state {
case .normal:
Expand Down
Loading