Skip to content

Commit a18f030

Browse files
authored
fix: theme support for text fields input and place holder values (#100)
* fix: theme support for text fields input and place holder values * remove extra newline char
1 parent d197cac commit a18f030

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

Sources/Authenticator/Views/Primitives/PasswordField.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct PasswordField: View {
6565
}
6666
}
6767
.textFieldStyle(.plain)
68+
.foregroundColor(foregroundColor)
6869
.frame(height: Platform.isMacOS ? 20 : 25)
6970
.padding([.top, .bottom, .leading], theme.components.field.padding)
7071
#if os(iOS)
@@ -86,10 +87,10 @@ struct PasswordField: View {
8687

8788
@ViewBuilder private func createInput() -> some View {
8889
if isShowingPassword {
89-
SwiftUI.TextField(placeholder, text: $text)
90+
SwiftUI.TextField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
9091
.focused($focusedField, equals: .plain)
9192
} else {
92-
SwiftUI.SecureField(placeholder, text: $text)
93+
SwiftUI.SecureField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
9394
.focused($focusedField, equals: .secure)
9495
}
9596
}
@@ -98,6 +99,23 @@ struct PasswordField: View {
9899
return focusedField != nil
99100
}
100101

102+
private func createPlaceHolderView(label: String) -> SwiftUI.Text {
103+
let textView = SwiftUI.Text(label)
104+
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
105+
.font(theme.fonts.body)
106+
textView.accessibilityHidden(true)
107+
return textView
108+
}
109+
110+
private var foregroundColor: Color {
111+
switch validator.state {
112+
case .normal:
113+
return theme.colors.foreground.secondary
114+
case .error:
115+
return theme.colors.foreground.error
116+
}
117+
}
118+
101119
private var showPasswordButtonColor: Color {
102120
switch validator.state {
103121
case .normal:

Sources/Authenticator/Views/Primitives/PhoneNumberField.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct PhoneNumberField: View {
6969
.frame(width: 1)
7070
.overlay(theme.colors.border.primary)
7171

72-
SwiftUI.TextField(placeholder, text: $phoneNumber)
72+
SwiftUI.TextField("", text: $phoneNumber, prompt: createPlaceHolderView(label: placeholder))
7373
.disableAutocorrection(true)
7474
.focused($focusedField, equals: .phoneNumber)
7575
.onChange(of: phoneNumber) { newValue in
@@ -100,6 +100,7 @@ struct PhoneNumberField: View {
100100
"authenticator.field.phoneNumber.label".localized()
101101
))
102102
.textFieldStyle(.plain)
103+
.foregroundColor(foregroundColor)
103104
.frame(height: Platform.isMacOS ? 20 : 25)
104105
.padding([.top, .bottom, .leading], theme.components.field.padding)
105106
#if os(iOS)
@@ -124,6 +125,14 @@ struct PhoneNumberField: View {
124125
}
125126
}
126127

128+
private func createPlaceHolderView(label: String) -> SwiftUI.Text {
129+
let textView = SwiftUI.Text(label)
130+
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
131+
.font(theme.fonts.body)
132+
textView.accessibilityHidden(true)
133+
return textView
134+
}
135+
127136
private var foregroundColor: Color {
128137
switch validator.state {
129138
case .normal:

Sources/Authenticator/Views/Primitives/TextField.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct TextField: View {
5151
isFocused: isFocused
5252
) {
5353
HStack {
54-
SwiftUI.TextField(placeholder, text: $text)
54+
SwiftUI.TextField("", text: $text, prompt: createPlaceHolderView(label: placeholder))
5555
.disableAutocorrection(true)
5656
.focused($isFocused)
5757
.onChange(of: text) { text in
@@ -65,6 +65,7 @@ struct TextField: View {
6565
}
6666
}
6767
.textFieldStyle(.plain)
68+
.foregroundColor(foregroundColor)
6869
.frame(height: Platform.isMacOS ? 20 : 25)
6970
.padding([.top, .bottom, .leading], theme.components.field.padding)
7071
#if os(iOS)
@@ -82,6 +83,23 @@ struct TextField: View {
8283
}
8384
}
8485

86+
private func createPlaceHolderView(label: String) -> SwiftUI.Text {
87+
let textView = SwiftUI.Text(label)
88+
.foregroundColor(theme.colors.foreground.disabled.opacity(0.6))
89+
.font(theme.fonts.body)
90+
textView.accessibilityHidden(true)
91+
return textView
92+
}
93+
94+
private var foregroundColor: Color {
95+
switch validator.state {
96+
case .normal:
97+
return theme.colors.foreground.secondary
98+
case .error:
99+
return theme.colors.foreground.error
100+
}
101+
}
102+
85103
private var clearButtonColor: Color {
86104
switch validator.state {
87105
case .normal:

0 commit comments

Comments
 (0)