Skip to content

Instantly share code, notes, and snippets.

@dgdavid
Last active May 22, 2023 15:18
Show Gist options
  • Save dgdavid/b91f18c4f20cf1e2c34b715201c43e0b to your computer and use it in GitHub Desktop.
Save dgdavid/b91f18c4f20cf1e2c34b715201c43e0b to your computer and use it in GitHub Desktop.

The device selector

We've decided to display more information for each available device to ease the process of selecting the right one when the user has plenty of them (or maybe just more than one).

Iván proposed a kind of gifted list for presenting the devices and their information to the users in a straightforward way, no matter if the system has only a few devices (or even just one) or a bunch of them. Sadly, neither the native <select> HTML element nor the PF4/Select component are suitable candidates for laying out the proposal.

Click to show/hide the proposed selector

Screenshot_from_2023-05-10_10-52-02

We could try to build a list based on a pile of <input type="radio" />/PF4/Radio options for single selection or <input type="checkbox" />/PF4/Checkbox for multiple selections. But there could be some usability issues because of a few details we're not going to cover here (like, for example, the need to hide the input but keep the focus on its parent element) .

Another option to evaluate is the PF4/Datalist component. However, it looks like we'd need to apply too much CSS hacking to make the selector look like the proposed one.

Hence, this PR proposes the use of a simple unordered list for implementing the proposed selector but bearing in mind the Listbox pattern to make it accessible.

This very rough first version does not pretend to be perfect, especially in terms of usability since the keyboard management is not implemented becasue we are committed to be as agile as possible. Thus, releasing the selector to be tested by sigth users seems a reasonable compromise for gathering early feedback and know whether it really suits our needs.

Click to show/hide the WIP selector

Screenshot from 2023-05-15 16-42-04

In addition, there is a reason for not fully implementing the Listbox pattern by ourselves: the open source Adobe's react-aria library. If we do not find a better option in our current ecosystem, we can evaluate adding react-aria as a dependency to provide accessibility and behavior according to WAI-ARIA Authoring Practices.

At the time of writing there are at least two approaches to using this library:

  • to use the useListBox hook

  • to use the ListBox component (in alpha at the time of writing)

Other notes

  • Listbox options cannot contain interactive content. This is important because if we plan to add interactivity to the listbox items, we should use the Grid pattern instead. Nonetheless, I think we should consider carefully whether making the selector too crowded and complicated in the future is really necessary. In any case, switching from one pattern to another does not look painful.

  • Just in case you wonder about it, using a list of <button>s is not an option becuase they are not designed for selecting options and only allows phrasing content. Of course, we could do it thanks to JavaScript and CSS tweaks, but using elements to do things they were not intended for is definetly a bad idea.

@dgdavid
Copy link
Author

dgdavid commented May 16, 2023

the open source Adobe's react-aria library

Which is licensed under the Apache License 2.0 https://github.com/adobe/react-spectrum/blob/main/LICENSE

@dgdavid
Copy link
Author

dgdavid commented May 17, 2023

@dgdavid
Copy link
Author

dgdavid commented May 22, 2023

See WIP at openSUSE/agama#578

Where we started the selector implementation on top of an <ul> but with an initial implementation of the mentioned Listbox pattern. That's, changing the default roles from list to listbox and listitem to option.

In other words, changing from structure to widget children, which became them

an interactive component.

Accordingly, the cursor: pointer CSS rule has been added to these options for hinting the sighted people about the interactivity of the selector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment