Page MenuHomePhabricator

ChipInput: Add menu functionality
Open, MediumPublic

Description

Background goal

Right now, ChipInput allows the user to add chips with whatever values they want, and doesn't suggest values. We should supporting adding a Menu below the input to suggest values, and support restricting the values that can be added to only those that appear in the menu.

Known use cases

FilterChipInput - UserPreferences.gif (293×600 px, 595 KB)
ChipInput with menu in User's preferences.
Screenshot 2024-02-15 at 19.08.02.png (1×1 px, 180 KB)
T357710: Page titles selector control in Community Configuration.
Screenshot 2024-02-15 at 19.00.45.png (1×1 px, 165 KB)
T357708: Namespaces selector control in Community Configuration.
Captura de tela 2024-05-21 173944.png (290×1 px, 32 KB)
Commons/Wikiversity from T365532: Add Lookup component based on ChipInput to Codex.
Captura de pantalla 2024-05-23 a las 18.19.52.png (1×1 px, 588 KB)
Multiblock project

Design spec

Guidelines

Open questions

  • What's the most straightforward way to enable configuration of the 3 different types of ChipInputs: only arbitrary content (no menu), only menu options, or menu options + arbitrary content? The OOUI MenuTagMultiselectWidget has an allowArbitrary property for this purpose, should we do something similar?
  • Assuming we use a similar API to Lookup's (emit an input event and expect the parent component to update the menu-items prop), how do we make it easy for the parent component to not add a menu, without keeping the input in the pending state forever because we're waiting for menu-items to be updated?
    • Perhaps this could be done by making menu-items optional, with a default value of null rather than [], to signify that no menu is used?
  • What's the best way to de-duplicate logic between this new feature and the Lookup component? We can't use the Lookup component inside ChipInput because we can't achieve the single input UI with the existing TextInput, which must work without JavaScript. Should we copy over the Lookup code to ChipInput, or try to share it in a composable?

Acceptance criteria (or Done)

Design

  • Design the Figma spec sheet and document its Guidelines T366006
  • Update the component in the Figma library. This step will be done by a DST member.
  • Update the ChipInput Guidelines including this new case

Code

  • Implement the component's updates in Codex
  • Demonstrate the 2 new types of ChipInputs: with menu and only allowing selection or menu items, or with menu but also allowing arbitrary user-submitted options

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Fwiw, CommunityConfiguration has implemented two components using this pattern: T357710: Page titles selector control and T357708: Namespaces selector control. Just mentioning here for an eventual refactor when Codex implements this.

One "not accurate" behavior we left for follow-up improvements is the menu item select event handling. In our current implementation the menu is closed after a click on a menu item. That is not suitable for a multi-select component in which the user is expected to select more than one element. In this case the menu should be left open until the field looses its focus. Maybe we could make this a prop for MenuItem component, eg: closeAfterMenuClick: false (default to true).

CCiufo-WMF triaged this task as Medium priority.May 14 2024, 4:31 PM
CCiufo-WMF moved this task from Backlog to Up Next on the Design-System-Team board.

I've created the Figma spec sheet and Guidelines for the ChipInput with menu functionality in T366006.

As discussed with @AnneT, we aim to integrate both ChipInput variants, with and without the menu, into the existing ChipInput component. It will feature the following props:

Types of ChipInput

There will be 3 type of ChipInput based on how the chips are created:

  1. Custom input (current version implemented):
chips can be created by typing and then pressing the Enter key, clicking outside the input, or tabbing out.
  2. Preset options:
chips can only be created by selecting the predefined menu options. If there are no results for the text typed by the user, a non-interactive "no results" message will be displayed within the menu.
  3. Custom input and preset options:
users can either select predefined options from the menu or add custom chips by typing and then pressing the Enter key, clicking outside the input, or tabbing out.

image.png (1×1 px, 148 KB)

Selected items within the menu

When preset options are available within a menu, the selected menu items will become chips. There are 2 ways of showing these selected menu items in the menu:

  1. Selected menu items disappear from the menu once converted to chips.
  2. Selected menu items remain displayed in the menu as chips.

I recommend not displaying selected items in the menu when they are created as chips (1) to improve user experience, since it will be easier for the user to detect which remaining menu items they can include as chips. Please review both options in this Figma prototype.

Captura de pantalla 2024-06-07 a las 11.51.24.png (918×2 px, 119 KB)

Optional stat icon

To maintain consistency with other form items (TextInput, TextArea, Select, etc.), the ChipInput will include an optional start icon. The start icon will be visible only when no chips are included within the input, to prevent overcrowding. However, the start icon will always be visible in the version where chips are included outside the input. Please review both options in [[ To maintain consistency with other form items, the ChipInput will include an optional start icon. The start icon will be visible only when no chips are included within the input, to prevent overcrowding. However, the start icon will always be visible in the version where chips are included outside the input. Please review both options in this [[ https://www.figma.com/proto/V8MBvInCI3mXB5LNMhRzJF/Chip-Input---T337095?page-id=2101%3A62033&node-id=2101-63118&t=EymEpuWtNNrJSDId-0&scaling=min-zoom&starting-point-node-id=2101%3A63118 | Figma prototype ]].

Captura de pantalla 2024-06-07 a las 11.48.02.png (922×1 px, 84 KB)