Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KRadioButton: Improve flexibility and accessibility of labels #348

Open
MisRob opened this issue Aug 12, 2022 · 4 comments
Open

KRadioButton: Improve flexibility and accessibility of labels #348

MisRob opened this issue Aug 12, 2022 · 4 comments
Assignees
Labels
category: library Shared code library Component: KRadioButton DEV: frontend product: Kolibri Relevant to a specific issue in Kolibri TAG: a11y TODO: needs decisions Further discussion and planning necessary type: proposal New feature or request

Comments

@MisRob
Copy link
Member

MisRob commented Aug 12, 2022

Product

Kolibri

Example: choosing a new super admin when changing facility

Desired behavior

(1) KRadioButton can receive HTML label content

So that we can easily use components to render label content, for example, this radio button label

Screenshot from 2022-08-12 12-58-46

can't be provided as mere text as it's generated by KLabeledIcon component:

<KLabeledIcon :icon="isCoach ? 'coach' : 'person'" :label="user.full_name" />

(2) KRadioButton uses explicit labels

  • Explicit labels are labels that are linked to input via its id passed to <label>'s for attribute.

  • In support of (3)

  • Explicit labels are said to work better in regards to a11y:

    Generally, explicit labels are better supported by assistive technology. (W3C)

(3) <label> can be defined outside of KRadioButton

<label for="firstname">First name:</label>
<KRadioButton id="firstname" />
  • To be able to work with <label> the same way we'd work with it when using it together with the native <input> that KRadioButton models:
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname">
  • To have control in regards to <input> and <label> order
  • For more flexibility when dynamically switching between KCheckbox and KRadioButton when the label is the same without the need to duplicate label code (useful especially for more complex labels that are generated by other components):
<KCheckbox v-if="allowMultiple" id="select-user" />
<KRadioButton v-else id="select-user" />
<label for="select-user">
   <KLabeledIcon :icon="isCoach ? 'coach' : 'person'" :label="user.full_name" />
</label>
  • For this to work, we also need to be able to pass id to KRadioButton so that we can use it in for attribute of label.

Summary

Label content could be provided in several ways

(a) Simple text via the label property
(b) HTML content via slot
(c) Independently of KRadioButton

In regards to (a) and (b), when <label> would be rendered inside of KRadioButton, we'd use explicit labels. To achieve explicit labels support for (c), KRadioButton will need to receive its inside input's id from outside via a prop.

Current behavior

  • KRadioButton only supports passing text for the label via the label property
  • It uses implicit labels (<input> wrapped in <label> without having these two linked with id and for)

The Value Add

  • Flexibility, efficiency
  • Explicit labels improve accessibility

Possible Tradeoffs

  • In more advanced use-cases (b) and (c), developers would need to make sure not to forget about label text truncation instead of relying on internal text truncation that works when label text is provided via the label property.
  • Since there would be more ways to label radio button, we couldn't throw an error anymore when currently required label property would not be provided which is helpful to make sure we don't forget to label

However, I think there's no need to limit ourselves in regards to supporting more complex scenarios. To solve this, I'd suggest that in documentation, we encourage (a) whenever possible, provide usage examples, and include truncation and a11y warnings for other use-cases.

@nucleogenesis
Copy link
Member

Since there would be more ways to label radio button, we couldn't throw an error anymore when currently required label property would not be provided which is helpful to make sure we don't forget to label

could we check in mounted whether the slot or prop are used and if neither are, throw an error - if even if only in dev?

@MisRob
Copy link
Member Author

MisRob commented Aug 16, 2022

@nucleogenesis Yes, that's a good idea

@MisRob
Copy link
Member Author

MisRob commented Aug 18, 2022

In light of #350, this tradeoff

In more advanced use-cases (b) and (c), developers would need to make sure not to forget about label text truncation instead of relying on internal text truncation that works when label text is provided via the label property.

may not be tradeoff, but actually the desired behavior

@MisRob MisRob added the TODO: needs decisions Further discussion and planning necessary label Aug 10, 2023
@nucleogenesis nucleogenesis added this to the KDS Priority Triage milestone Oct 31, 2023
@MisRob
Copy link
Member Author

MisRob commented Mar 6, 2024

Assigning myself to update requirements here

@MisRob MisRob self-assigned this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: library Shared code library Component: KRadioButton DEV: frontend product: Kolibri Relevant to a specific issue in Kolibri TAG: a11y TODO: needs decisions Further discussion and planning necessary type: proposal New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants