lukeredpath / swift-responsive-textfield

A SwiftUI wrapper around UITextField with binding-based state and responder control
Apache License 2.0
86 stars 13 forks source link

Allow users to specify an accessibility identifier for the field #13

Closed leopic closed 1 year ago

leopic commented 1 year ago

While trying to write UI tests for a view using this package I realized there was no way to specify an identifier.

lukeredpath commented 1 year ago

@leopic thanks for the PR - out of interest, does attaching an identifier to the ResponsiveTextView using SwiftUI's accessibility APIs not work?

leopic commented 1 year ago

@lukeredpath it did not on my first attempt, let me try one more time before merging.

lukeredpath commented 1 year ago

@leopic actually, I think this might be better served using the existing configuration system, which would allow you to configure as many accessibility properties as you need, for example:

public extension ResponsiveTextField.Configuration {
  static func accessibile(identifier: String) {
    $0.accessibilityIdentifier = identifier
    // any other accessibility traits/properties set here
  }
}

And then pass this in when creating the text field:

...
configuration: .accessible(identifier: "foo")

Or if you're already using a configuration:

...
configuration: .combine(.someExisting, .accessible(identifier: "foo"))
leopic commented 1 year ago

@lukeredpath it did actually work, my bad!

No need for this PR at all, but I did like your approach better, to be honest 😅 .

Thanks anyway.