macOS: disable text selection on macOS 15

This commit is contained in:
Lukas
2026-08-10 11:39:53 +02:00
parent 49e4df7833
commit 4b9d589bcb

View File

@@ -132,8 +132,19 @@ enum BackportNSGlassStyle {
#endif
}
/// Backported `TextField` that supports text selection on macOS 15/iOS 18 and up. The `selection`
/// has no effect on versions below macOS 15/iOS 18.
/// Backported `TextField` that supports text selection on macOS 26/iOS 18 and up. The `selection`
/// has no effect on versions below macOS 26/iOS 18.
///
/// Although the API is available from macOS 15, we force it to be 26. Because on macOS 15,
/// SwiftUI will crash when deleting texts, even for this simple example.
///
/// struct ContentView: View {
/// @State private var text = ""
/// @State private var selection: TextSelection?
/// var body: some View {
/// TextField("Search", text: $text, selection: $selection)
/// }
/// }
struct BackportSelectionTextField: View {
private let titleKey: LocalizedStringKey
@Binding private var text: String
@@ -150,7 +161,7 @@ struct BackportSelectionTextField: View {
}
var body: some View {
if #available(iOS 18.0, macOS 15, *) {
if #available(iOS 18.0, macOS 26, *) {
TextField(
titleKey,
text: _text,