From f56f3d687c90f2dc614b99b4849085dd13fc6b3e Mon Sep 17 00:00:00 2001 From: romchornyi Date: Sat, 31 Oct 2026 15:22:27 +0200 Subject: [PATCH 1/3] wip: represent SwitchView as a native Toggle for accessibility Co-Authored-By: Claude Opus 5.5 --- Sources/DashUIKit/Components/Switch/SwitchView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/DashUIKit/Components/Switch/SwitchView.swift b/Sources/DashUIKit/Components/Switch/SwitchView.swift index 3e260bc..98c5eb5 100644 --- a/Sources/DashUIKit/Components/Switch/SwitchView.swift +++ b/Sources/DashUIKit/Components/Switch/SwitchView.swift @@ -42,9 +42,10 @@ public struct SwitchView: View { .animation(.easeInOut(duration: Constants.animationDuration), value: isOn) .contentShape(Rectangle()) .onTapGesture { isOn.toggle() } - .accessibilityAddTraits(.isToggle) - .accessibilityValue(Text(isOn ? Constants.onValue : Constants.offValue)) - .accessibilityAction { isOn.toggle() } + .accessibilityRepresentation { + Toggle(isOn: $isOn) { EmptyView() } + .labelsHidden() + } } private var trackFill: Color { From bde077d2f8586a36bd6d89bb240499a35899510b Mon Sep 17 00:00:00 2001 From: romchornyi Date: Sat, 31 Oct 2026 15:55:47 +0200 Subject: [PATCH 2/3] fix: read SwitchView to VoiceOver like a native toggle SwitchView set a hand-made accessibility value "On"/"Off" that DashUIKit never localizes, so VoiceOver read it in English in every locale. Its accessibility representation is now a label-hidden Toggle, so the value, traits, disabled state and activation are the system control's, and VoiceOver speaks the state in the user's language. Documents SwitchView in Buttons & inputs and the catalogs. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + .../Components/Switch/SwitchView.swift | 12 ++++++++-- docs/README.md | 5 ++-- docs/buttons-and-inputs.md | 23 +++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6660d92..9b58ac0 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ a component already exists before building your own. |---|---|---| | `DashButton` | Themed button — 4 sizes × 11 styles, icons, loading, full-width | [Buttons & inputs](docs/buttons-and-inputs.md) | | `DashSwitch` | DS-tinted toggle | [Buttons & inputs](docs/buttons-and-inputs.md) | +| `SwitchView` | DS-drawn switch; a native `Toggle` to VoiceOver | [Buttons & inputs](docs/buttons-and-inputs.md) | | `SearchBar` | Search field with an animated cancel button | [Buttons & inputs](docs/buttons-and-inputs.md) | | `AddressFieldView` | Labeled text field (label / field / help text) with optional QR, clear and error state | [Buttons & inputs](docs/buttons-and-inputs.md) | | `Criteria` | Requirement check-list — `Criterion` rows in six states | [Buttons & inputs](docs/buttons-and-inputs.md) | diff --git a/Sources/DashUIKit/Components/Switch/SwitchView.swift b/Sources/DashUIKit/Components/Switch/SwitchView.swift index 98c5eb5..cacde6d 100644 --- a/Sources/DashUIKit/Components/Switch/SwitchView.swift +++ b/Sources/DashUIKit/Components/Switch/SwitchView.swift @@ -7,6 +7,14 @@ import SwiftUI +/// The design system's switch: a blue track with a white thumb, drawn by hand +/// rather than tinting the system `Toggle`. +/// +/// To assistive technologies it is a native `Toggle` with a hidden label: the +/// same traits, the same state value, which VoiceOver speaks in the user's +/// language, the same disabled state, and activation flips `isOn`. Give it a +/// name with `.accessibilityLabel(_:)`, or let a row that combines its children +/// supply one. public struct SwitchView: View { private struct Constants { @@ -18,8 +26,6 @@ public struct SwitchView: View { static let switchTrackPadding: CGFloat = 2 static let switchTrackRadius: CGFloat = 1000 static let animationDuration: Double = 0.2 - static let onValue = NSLocalizedString("On", bundle: .module, comment: "DashUIKit") - static let offValue = NSLocalizedString("Off", bundle: .module, comment: "DashUIKit") } @Environment(\.isEnabled) private var isEnabled @@ -42,6 +48,8 @@ public struct SwitchView: View { .animation(.easeInOut(duration: Constants.animationDuration), value: isOn) .contentShape(Rectangle()) .onTapGesture { isOn.toggle() } + // The system control's semantics, not hand-made ones: VoiceOver + // localizes a toggle's state only when it comes from a real `Toggle`. .accessibilityRepresentation { Toggle(isOn: $isOn) { EmptyView() } .labelsHidden() diff --git a/docs/README.md b/docs/README.md index 626a7e1..ae29a38 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,8 +12,8 @@ and callbacks; they render and report intent. They require `import DashUIKit` an - **[Foundation](foundation.md)** — design tokens: colors (`Color.dash.*`), typography (`Font.dash.*`, `.dashFont`, `DashTextStyle`), icons (`DashIconSource`, `Image(dash:)`), bundle access. -- **[Buttons & inputs](buttons-and-inputs.md)** — `DashButton`, `DashSwitch`, `SearchBar`, - `AddressFieldView`, `Criteria`, `SimpleSelect`, `NumericKeyboardView`. +- **[Buttons & inputs](buttons-and-inputs.md)** — `DashButton`, `DashSwitch`, `SwitchView`, + `SearchBar`, `AddressFieldView`, `Criteria`, `SimpleSelect`, `NumericKeyboardView`. - **[Amount & currency](amount-and-currency.md)** — `EnterAmountView`, `SwapAmountView`, `ReceiveEstimateView`, `DashAmount`, `DashBalanceView`, `DashPickerView`, `CurrencyOption`. @@ -72,6 +72,7 @@ and callbacks; they render and report intent. They require `import DashUIKit` an | `SimpleSelect` | [Buttons & inputs](buttons-and-inputs.md#simpleselect) | | `SuccessIllustration` | [Feedback](feedback.md#successillustration--errorillustration) | | `SwapAmountView` | [Amount & currency](amount-and-currency.md#swapamountview) | +| `SwitchView` | [Buttons & inputs](buttons-and-inputs.md#switchview) | | `SystemMessageView` | [Feedback](feedback.md#systemmessageview) | | `Toast` (`ToastStyle`) | [Feedback](feedback.md#toast) | | `TopIntroView` | [Navigation & containers](navigation-and-containers.md#topintroview) | diff --git a/docs/buttons-and-inputs.md b/docs/buttons-and-inputs.md index 0e2cb7b..ab833fe 100644 --- a/docs/buttons-and-inputs.md +++ b/docs/buttons-and-inputs.md @@ -59,6 +59,29 @@ DashSwitch(isOn: $isOn) --- +## SwitchView + +File `Components/Switch/SwitchView.swift` + +The design system's switch: the DS track and thumb drawn in SwiftUI, on iOS and macOS. +`MenuItem`'s `.toggle` accessory uses it. It takes its enabled state from the environment, +so `.disabled(true)` dims it and stops the tap. + +```swift +@State private var isOn = false +SwitchView(isOn: $isOn) + .accessibilityLabel("Advanced mode") // optional, see below +``` + +To assistive technologies and UI tests it is a native `Toggle` with a hidden label: the +same traits, the same state value, which VoiceOver speaks in the user's language, dimmed +when disabled, and a double-tap flips `isOn`. Its own label is empty: name it with `.accessibilityLabel(_:)`, or put it in a row +that combines its children (`.accessibilityElement(children: .combine)`), which reads the +row's text and the switch's state as one element. UI tests read the state as the value +`"1"` / `"0"`, as for any `Toggle`. + +--- + ## SearchBar File `Components/SearchBar.swift` · **UIKit only** From 83bb23e6a4488f7c9a7661d8707566cffc850754 Mon Sep 17 00:00:00 2001 From: romchornyi Date: Sat, 31 Oct 2026 15:58:42 +0200 Subject: [PATCH 3/3] fix: pin the switch style of SwitchView's accessibility toggle On macOS the default Toggle style is a checkbox, and a host's toggleStyle would also reach the representation. Docs: say when to use SwitchView vs DashSwitch, and that the 1/0 value is what iOS UI tests read. Co-Authored-By: Claude Opus 5.5 --- .../DashUIKit/Components/Switch/SwitchView.swift | 3 +++ docs/buttons-and-inputs.md | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/DashUIKit/Components/Switch/SwitchView.swift b/Sources/DashUIKit/Components/Switch/SwitchView.swift index cacde6d..08a9391 100644 --- a/Sources/DashUIKit/Components/Switch/SwitchView.swift +++ b/Sources/DashUIKit/Components/Switch/SwitchView.swift @@ -50,9 +50,12 @@ public struct SwitchView: View { .onTapGesture { isOn.toggle() } // The system control's semantics, not hand-made ones: VoiceOver // localizes a toggle's state only when it comes from a real `Toggle`. + // The style is pinned so the role stays a switch on macOS, where the + // default is a checkbox, and under a host's `toggleStyle`. .accessibilityRepresentation { Toggle(isOn: $isOn) { EmptyView() } .labelsHidden() + .toggleStyle(.switch) } } diff --git a/docs/buttons-and-inputs.md b/docs/buttons-and-inputs.md index ab833fe..84edb1a 100644 --- a/docs/buttons-and-inputs.md +++ b/docs/buttons-and-inputs.md @@ -65,7 +65,8 @@ File `Components/Switch/SwitchView.swift` The design system's switch: the DS track and thumb drawn in SwiftUI, on iOS and macOS. `MenuItem`'s `.toggle` accessory uses it. It takes its enabled state from the environment, -so `.disabled(true)` dims it and stops the tap. +so `.disabled(true)` dims it and stops the tap. Use it where the DS switch is drawn; +`DashSwitch` is the system switch with the DS tint, UIKit only. ```swift @State private var isOn = false @@ -73,11 +74,12 @@ SwitchView(isOn: $isOn) .accessibilityLabel("Advanced mode") // optional, see below ``` -To assistive technologies and UI tests it is a native `Toggle` with a hidden label: the -same traits, the same state value, which VoiceOver speaks in the user's language, dimmed -when disabled, and a double-tap flips `isOn`. Its own label is empty: name it with `.accessibilityLabel(_:)`, or put it in a row -that combines its children (`.accessibilityElement(children: .combine)`), which reads the -row's text and the switch's state as one element. UI tests read the state as the value +To assistive technologies and UI tests it is a native switch-style `Toggle` with a hidden +label: the same traits, the same state value, which VoiceOver speaks in the user's +language, dimmed when disabled, and a double-tap flips `isOn`. Its own label is empty: +name it with `.accessibilityLabel(_:)`, or put it in a row that combines its children +(`.accessibilityElement(children: .combine)`), which then reads the row's text as the +label and the switch's state as the value. On iOS, UI tests read the state as the value `"1"` / `"0"`, as for any `Toggle`. ---