From 496ee2ff7de20ab9518ffe5a9ddc2a7a89599ee0 Mon Sep 17 00:00:00 2001 From: Kaede Akino Date: Mon, 28 Sep 2026 17:24:13 +0800 Subject: [PATCH] fix(forms): place secret visibility buttons inside inputs --- .../RevealableSecretField.swift | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Frameworks/TermindPresentation/RevealableSecretField.swift b/Frameworks/TermindPresentation/RevealableSecretField.swift index bb112d08..15fe0ef0 100644 --- a/Frameworks/TermindPresentation/RevealableSecretField.swift +++ b/Frameworks/TermindPresentation/RevealableSecretField.swift @@ -20,6 +20,24 @@ public struct RevealableSecretField: View { } public var body: some View { + Group { + #if os(macOS) + LabeledContent { + input + } label: { + Text(title) + } + #else + input + #endif + } + .onDisappear { isRevealed = false } + .onChange(of: scenePhase) { _, phase in + if phase != .active { isRevealed = false } + } + } + + private var input: some View { HStack(spacing: 6) { Group { if isRevealed { @@ -28,6 +46,8 @@ public struct RevealableSecretField: View { SecureField(title, text: $text, prompt: prompt) } } + .textFieldStyle(.plain) + .labelsHidden() Button { isRevealed.toggle() @@ -40,9 +60,8 @@ public struct RevealableSecretField: View { .accessibilityLabel( isRevealed ? Text(AppStrings.Settings.hideSecret) : Text(AppStrings.Settings.showSecret)) } - .onDisappear { isRevealed = false } - .onChange(of: scenePhase) { _, phase in - if phase != .active { isRevealed = false } - } + .padding(.horizontal, 6) + .padding(.vertical, 4) + .background(.quaternary.opacity(0.5), in: .rect(cornerRadius: 6)) } }