Skip to content

Commit

Permalink
Merge pull request #176 from iZettle/form-view-accessibility
Browse files Browse the repository at this point in the history
PLT-2592 Expose the Contents of a `FormView` as Accessibility Elements
  • Loading branch information
Alasdair Baxter authored Feb 1, 2022
2 parents da0094f + ca07ae4 commit 637e6c7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.3.1

- Improved the accessibility of `FormView` by making it an accessibility container comprising the visible rows from each of its visible sections.

# 3.3.0

- Added (backwards compatible) support for supplying an `accessibilityValue` to `ValueField` through `TextEditor`.
Expand Down
17 changes: 17 additions & 0 deletions Form/FormView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ public class FormView: UIStackView, DynamicStylable {
}

public extension FormView {

override var accessibilityElements: [Any]? {
get {
let visibleSections = sections.filter { !$0.isHidden }

var elements: [Any] = []
for section in visibleSections {
elements.append(contentsOf: section.accessibilityElements ?? [])
}

return elements
}

//swiftlint:disable:next unused_setter_value
set { /* Always computed */ }
}

var sections: [SectionView] {
return orderedViews.compactMap { $0 as? SectionView }
}
Expand Down
23 changes: 23 additions & 0 deletions Form/SectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ extension SectionView: SubviewOrderable {
}

public extension SectionView {

override var accessibilityElements: [Any]? {
get {
var elements: [Any] = []

if let header = headerView {
elements.append(header)
}

let visibleRows = orderedViews.filter { !$0.isHidden }
elements.append(contentsOf: visibleRows)

if let footer = footerView {
elements.append(footer)
}

return elements
}

//swiftlint:disable:next unused_setter_value
set { /* Always computed */ }
}

var headerView: UIView? {
return header.view
}
Expand Down

0 comments on commit 637e6c7

Please sign in to comment.