Repository navigation
Allow ButtonState to carry an accessibility identifier #374
Replies: 1 comment 3 replies
|
Hi @GMetaxakis, in the future please rewrite the AI generated text in your own words, and try to focus on the core problem. You simply want I am not super familiar with UI tests, so one question I have is is it sufficient to support If it does work to put it just on the text, not the button, then it is very easy to support and we'd welcome a PR. There's an enum you can add a single case to and then fix the compiler errors where necessary. If that does not work, then the modifier infrastructure from |
Uh oh!
There was an error while loading. Please reload this page.
ButtonStatecan carry an accessibility label (viaTextState) but not an accessibility identifier, and the identifier is what UI tests actually match on. That makes alerts modelled withAlertStateunreachable from a UI test that addresses elements by id.Where this bites
We're migrating a fairly large app's alerts onto
AlertState, and hit exactly one blocker. An onboarding confirmation alert has:Our E2E suite waits on and taps that id. Converting the alert to
AlertStatecompiles, behaves identically, and silently breaks the test — the identifier has nowhere to live onButtonState, so the element is no longer addressable. A green build, a red suite, and nothing in between to catch it. We left that one alert hand-written.Why there's no workaround at the view layer
This is the part that differs from #52 (
TextFieldState). There the advice is to hold the extra state in the domain and derive the binding in the view, which works because the view still owns the text field.Here it doesn't:
.alert($store.scope(state:action:))renders the buttons from[ButtonState]itself, so there is no point at which I can attach a modifier to the button it builds. The only escape is to stop usingAlertStatefor that alert, which is what we did.There's already precedent for this shape
Accessibility metadata is not a foreign concept to
ButtonState—TextStatecarries it and both render paths honour it:Sources/UIKitNavigation/Navigation/UIAlertController.swift:126—self.accessibilityLabel = button.label.accessibilityLabel.map { String(state: $0) }Sources/SwiftNavigation/TextState.swift:558— the.accessibilityLabelcase maps toText.accessibilityLabel(_:)So the gap is specifically the identifier.
grep -rn accessibilityIdentifier Sources/returns nothing.Possible shapes
No strong opinion on which fits the library best:
accessibilityIdentifieronButtonState, applied alongside the existing label handling in both paths.TextStatemodifier, mirroring.accessibilityLabel(_:)— though an identifier is arguably a property of the control rather than its text.ButtonStateminimal.Happy to open a PR if one of these looks right.
swift-navigation 2.10.3.
All reactions