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

Chip/token pattern #2480

Open
brennanyoung opened this issue Sep 20, 2022 · 3 comments
Open

Chip/token pattern #2480

brennanyoung opened this issue Sep 20, 2022 · 3 comments

Comments

@brennanyoung
Copy link

brennanyoung commented Sep 20, 2022

A very common UI pattern is the "token" or "chip", typically used for filtering search results. (Are chips used anywhere else?)

These appear in (e.g.) ebay to show which filters are currently selected. Clicking the chip removes the filter.
There's a screenshot from ebay at: https://user-images.githubusercontent.com/1430985/172394076-094bf4fe-0b40-4eef-8ad3-cce311747302.png showing chips.

These are typically oval-shaped elements with a text label and (very often) a 'close button' which removes the chip from the filter.

I've seen a few discussions about whether the close button should be a distinct focus target, separate from the chip itself. I don't know what is the more correct thing.

Chips often appear in popup/dropdown menus, so there are some additional focus management issues to consider.

There have been a couple of attempts to introduce a new aria role for these elements, which are neither buttons nor checkboxes, for example:
w3c/aria#689
w3c/aria#1752

...but the consensus is rather lukewarm, and there are working accessible precedents out there "in the wild" so I don't expect any movement on this any time soon.

In practice, chips tend to be implemented as <a> elements, which is not an obvious choice.
Still, this non-obvious practice seems to be quite well-established. I assume it was well-chosen, but it is not documented anywhere.

For that reason, I would like to see an APG pattern document for filter chips/tokens, showing the practices which work well today. Ideally this would represent the chips in the context of a filter.

@brennanyoung
Copy link
Author

<a> seems to be contraindicated for chips that have a close box. (focusable elements are prohibited inside <a>)
<a> seems to be contraindicated for chips that have no href (naming not supported for <a> without href)

@brennanyoung
Copy link
Author

brennanyoung commented Nov 1, 2022

Usage notes that any forthcoming APG pattern guidance should address;

  • Where are these elements permitted to appear?
  • Some chips have a close box, but it's not a checkbox. What is it then?
  • Some behave more like toggle buttons (can't be dismissed, but can be 'unchecked'). Perhaps these should be implemented as button with aria-pressed?
  • Quite a few of the implementations "in the wild" support reordering of chips/tokens (typically by drag-and-drop). Suggest viable keyboard interface for this?
  • If a token is in focus and you press "Delete" on the keyboard perhaps it should behave as if the close box has been clicked. (If there is a close box). Possibly viable if a chip/token is implemented as <a> where a focusable closebox element is forbidden.

@JAWS-test
Copy link

Since there is no ARIA role for chips (I would like it if there was), I would use an unsorted list (ul element). The chips would be the list entries (li element). For the close buttons I use the button element. The close buttons contain the name of the chip in their label (aria-label="Delete [name of chip]").
The list (ul element) is labeled so that it is clear what the chips refer to (e.g. aria-label="Selected items from ...").
Instead of ul a sorted list (ol element) can be used if the order of the chips is relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants