Skip to content

Commit

Permalink
Merge pull request #2074 from Skyscanner/donburi/improve_accessibilit…
Browse files Browse the repository at this point in the history
…y_for_dateselector

BPKSearchInputSummary accessibility improvement
  • Loading branch information
brunomdac authored Oct 7, 2024
2 parents aef9fef + 65cfa15 commit 779014a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct BPKSearchInputSummary: View {
private let placeholder: String
private let inputPrefix: InputPrefix?
private var style: Style = .default

private var customAccessibilityValue: String?
private let readOnly: Bool
private let clearAction: ClearAction

Expand All @@ -57,12 +57,14 @@ public struct BPKSearchInputSummary: View {
inputPrefix: InputPrefix? = nil,
clearAction: ClearAction,
readOnly: Bool = false,
customAccessibilityValue: String? = nil,
_ text: Binding<String>
) {
self.placeholder = placeholder
self.inputPrefix = inputPrefix
self.clearAction = clearAction
self.readOnly = readOnly
self.customAccessibilityValue = customAccessibilityValue
self._text = text
}

Expand All @@ -77,9 +79,9 @@ public struct BPKSearchInputSummary: View {
.if(readOnly, transform: { view in
view.accessibilityElement()
})
.accessibilityValue(text.isEmpty ? placeholder : text)
.accessibilityValue(customAccessibilityValue ?? text)
.accessibilityLabel(placeholder)
.accessibilityAddTraits(readOnly ? [] : .isSearchField)
.accessibilityAddTraits(style == .focused ? .isSelected : [])
.focused($focused)
accessory
}
Expand Down
10 changes: 9 additions & 1 deletion Backpack-SwiftUI/SearchInputSummary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ By default, BPKSearchInputSummary provides an accessibility value and traits. Ho
```swift
BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { $text = "" }), text: $text)
.accessibilityLabel("Custom input field")
```
```

There is a built-in announcement of a current value. However, if it's necessary, the custom value could be passed as a parameter. It can be useful for announcing dates, for example.

```swift
BPKSearchInputSummary(placeholder: "Date", clearAction: .init(accessibilityLabel: "Clear", action: {}), customAccessibilityValue: , .constant("Mon 01 Jan"))
```

Accessibility Label is always a value from `placeholder` parameter.

0 comments on commit 779014a

Please sign in to comment.