diff --git a/DuckDuckGo/SecureVault/View/AutoRecalculatingKeyViewHostingView.swift b/DuckDuckGo/SecureVault/View/AutoRecalculatingKeyViewHostingView.swift new file mode 100644 index 0000000000..53e9a95e5a --- /dev/null +++ b/DuckDuckGo/SecureVault/View/AutoRecalculatingKeyViewHostingView.swift @@ -0,0 +1,28 @@ +// +// AutoRecalculatingKeyViewHostingView.swift +// +// Copyright © 2025 DuckDuckGo. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import SwiftUI + +final class AutoRecalculatingKeyViewHostingView: NSHostingView { + override func layout() { + super.layout() + + // Fix not being able to tab between TextFields by manually updating key view loop after SwiftUI has finished layout. This doesn't happen automatically because MainWindow sets autorecalculatesKeyViewLoop to false. + self.window?.recalculateKeyViewLoop() + } +} diff --git a/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift b/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift index 881b579b22..137b7bfe3e 100644 --- a/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift +++ b/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift @@ -462,7 +462,7 @@ final class PasswordManagementViewController: NSViewController { self.itemModel = itemModel - let view = NSHostingView(rootView: PasswordManagementLoginItemView().environmentObject(itemModel)) + let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementLoginItemView().environmentObject(itemModel)) replaceItemContainerChildView(with: view) } @@ -478,7 +478,7 @@ final class PasswordManagementViewController: NSViewController { self.itemModel = itemModel - let view = NSHostingView(rootView: PasswordManagementIdentityItemView().environmentObject(itemModel)) + let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementIdentityItemView().environmentObject(itemModel)) replaceItemContainerChildView(with: view) } @@ -494,7 +494,7 @@ final class PasswordManagementViewController: NSViewController { self.itemModel = itemModel - let view = NSHostingView(rootView: PasswordManagementNoteItemView().environmentObject(itemModel)) + let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementNoteItemView().environmentObject(itemModel)) replaceItemContainerChildView(with: view) } @@ -510,7 +510,7 @@ final class PasswordManagementViewController: NSViewController { self.itemModel = itemModel - let view = NSHostingView(rootView: PasswordManagementCreditCardItemView().environmentObject(itemModel)) + let view = AutoRecalculatingKeyViewHostingView(rootView: PasswordManagementCreditCardItemView().environmentObject(itemModel)) replaceItemContainerChildView(with: view) }