Giter Site home page Giter Site logo

Comments (11)

alexstine avatar alexstine commented on May 10, 2024 1

Agreed. Upvote.

from accessibility-code-examples.

JJdeGroot avatar JJdeGroot commented on May 10, 2024

Hi @pauljadam, thanks for raising this issue. This code sample was written by me. It's specifically about linking labels to input fields.

A shortcoming on iOS is that we don't have a way of linking labels to text fields. On the web we have <label for> and and Android we have labelFor. This is why the Android guidance doesn't include this workaround.

When using VoiceOver on iOS on a website with multiple <label for> and <input>, the focus moves from input field to input field when swiping right. The labels are skipped. However, the labels are focusable when you explore by touch.

Labels are not focusable when setting isAccessibilityElement to false on iOS. Therefore I do agree that labels on iOS should also remain focusable.

We still have to answer this question: what is the best work-around to programmatically associate a label on iOS with an input field?

Do we set the same accessibilityLabel twice, on both the label and the input field? For VoiceOver users this means they will hear the same label twice.

from accessibility-code-examples.

JJdeGroot avatar JJdeGroot commented on May 10, 2024

For SwiftUI we have accessibilityLabeledPair but haven't used it myself yet. Relevant discussion: https://stackoverflow.com/questions/73545427/pairing-two-elements-for-accessibility-purposes-with-accessibilitylabeledpairr

Maybe we can also backport this to UIKit? But first need a working code sample for SwiftUI.

from accessibility-code-examples.

pauljadam avatar pauljadam commented on May 10, 2024

I think that is a newer behavior on iOS where it sometimes skips over labels when swiping. It used to swipe through everything like a desktop screen reader always has when using arrow navigation. Labels should definitely be focusable on explore by touch! Thanks for taking my feedback!!

Since Apple has not given us a labelFor property we just have to manually set the .accessibilityLabel which is only one line of code.

SwiftUI example:
Text("Username")
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", text: $text)
.textFieldStyle(.roundedBorder)
.accessibilityLabel("Username")

It's only being set once, not twice. VoiceOver will hear it twice though as expected.

from accessibility-code-examples.

pauljadam avatar pauljadam commented on May 10, 2024

For SwiftUI we have accessibilityLabeledPair but haven't used it myself yet. Relevant discussion: https://stackoverflow.com/questions/73545427/pairing-two-elements-for-accessibility-purposes-with-accessibilitylabeledpairr

Maybe we can also backport this to UIKit? But first need a working code sample for SwiftUI.

I don't think that code actually works, like how heading levels in iOS don't actually work either.

from accessibility-code-examples.

JJdeGroot avatar JJdeGroot commented on May 10, 2024

I have updated the iOS code sample: 96ac5d6?diff=split

The SwiftUI behavior is equal to the UIKit behavior. We are in touch with a SwiftUI developer who will likely contribute code samples in Q1 2024. Thanks for the sample. A swift-ui branch will be created in the near-future and we will add all samples in one go.

I will keep this issue open for a little longer while there is still discussion on LinkedIn.

from accessibility-code-examples.

pauljadam avatar pauljadam commented on May 10, 2024

On iOS, there is no attribute to link a label to an input field. **We recommend combining** [UILabel](https://developer.apple.com/documentation/uikit/uilabel) with a [UITextField](https://developer.apple.com/documentation/uikit/uitextfield) or [UITextView](https://developer.apple.com/documentation/uikit/uitextview).

I'm not sure I understand this statement about combining the UILabel with TextField or TextView. There's no code showing how to do this so I can't test if it's a good a11y practice or not. It seems like an extra hack that's not required. I don't know what the behavior would be so I would avoid it.

from accessibility-code-examples.

JJdeGroot avatar JJdeGroot commented on May 10, 2024

@pauljadam there is a code sample using UILabel + UITextField to show how one could provide labels for input fields.

label.text = "Name"
field.accessibilityLabel = label.text

It's consistent with the guidance provided for other frameworks. It's showing a basic way to provide an accessible input field.

from accessibility-code-examples.

pauljadam avatar pauljadam commented on May 10, 2024

That part is fine, this part is the one I'm confused about?

We recommend combining UILabel with a UITextField or UITextView.

from accessibility-code-examples.

JJdeGroot avatar JJdeGroot commented on May 10, 2024

The "combining" part is about using a UILabel as label for an input field, such as UITextField or UITextView. How could we word this more clearly? @pauljadam

from accessibility-code-examples.

pauljadam avatar pauljadam commented on May 10, 2024

I was confused because I assume "combining" to me means to combine the focusable area of the 2 elements into one single element and my worry is that the label would not be focusable.

I would reword to say something like "Set the visible label text as the .accessibilityLabel of the input."

from accessibility-code-examples.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.