GlFilteredSearch: Improve option interactions
What does this MR do?
Generally refactors and improves the option rendering and interactivity. See the GitLab integration MR as well.
chore(GlFilteredSearch): Use boolean for default operator
This doesn't change any behaviour. It's just odd to use a string representation for a boolean.
chore(GlFilteredSearch): Make values and titles in options different
This makes it easier to spot if we're not treating values and titles properly. For instance, using the value as the title, or vice versa.
docs(GlFilteredSearch): Recommend index in suggestion keys
This also fixes a story which exhibited the incorrect behaviour. To reproduce it before this commit:
- Go to the "With Multi Select" story.
- Backspace into the "Assignee" token until only a "b" remains, and only the "User Beta" option is visible.
- Backspace once more, to display all the other user options.
- Press DownArrow once, and observe "User Beta" is selected.
- Press DownArrow once, and observe "User Alpha" is selected.
- Press DownArrow once, and observe "User Gamma" is selected.
With this commit, the order of the last three steps is now the correct "User Alpha", "User Beta", "User Gamma".
chore(GlFilteredSearch): Use async in Jest tests
Improves readability.
chore(GlFilteredSearch): Refactor Cypress tests
Improves readability.
refactor(GlFilteredSearch): Improve suggestion selection logic
This rewrites the suggestion selection tracking logic, and adds two test cases:
- One is a regression test, as it fails on the previous implementation.
- The other just increases test coverage for the new implementation.
This new implementation seems a bit over-engineered at first, but isn't really, since it makes it easier to switch to purely cyclic selection in future. That is, not allowing deselection of options via the arrow keys. This will be needed for the upcoming work to stop treating spaces specially.
See #2159 (closed) and !3226 (closed) for more detail.
feat(GlFilteredSearch): Improve option interactions
This changes several aspects of options lists:
- The first static option which case-insensitively contains the given
non-empty text is now selected automatically. This includes token
options of a search term, which previously were only selected when the
entire
valuewas typed out. Custom token components which use thesuggestionsslot are not affected. - Static options can now be rendered with a custom component by
providing a
componentproperty on them. This keeps the information about how to display the option near the option definition. - Token options (i.e., when choosing the type of token) can now be
rendered with a custom component by providing an
optionComponentproperty to the token definition inGlFilteredSearch'savailable-tokensprop. - Token option rendering is now delegated to
GlFilteredSearchTokenSegmentvia itsoptionsprop, deduplicating some display logic. - The
completeevent emitted by a title segment now passes the tokentypeinstead of itstitle. This is more consistent with othercompleteevents in the component tree, astypeis designed to be a unique value, whereastitleis designed to be a user-facing string. -
GlFilteredSearchTokenSegment'soptionTextFieldprop now defaults totitleinstead ofvalue.
This also reverts !3274 (merged) and !3318 (merged) (see below).
BREAKING CHANGE: GlFilteredSearch/GlFilteredSearchTerm's title
slots and GlFilteredSearchToken's title-option slot have been
removed. Similar functionality is available by setting the
optionComponent property on the given token object passed to
GlFilteredSearch's available-tokens prop. The component will be
given an option prop, which will be the option object representing the
token.
Part of #2159 (closed).
Screenshots
While this MR is mostly refactoring (working towards #2159 (closed)), it does have some visible changes:
| Before | After |
|---|---|
| simplescreenrecorder-2023-04-01_01.18.02 | simplescreenrecorder-2023-04-01_01.17.14 |
| simplescreenrecorder-2023-04-01_16.39.54 | simplescreenrecorder-2023-04-01_16.39.00 |
Does this MR meet the acceptance criteria?
Conformity
-
Code review guidelines. -
GitLab UI's contributing guidlines. -
If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer. -
If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer. -
If the MR changes a component's API, integration MR(s) have been opened in the following projects to ensure that the @gitlab/uipackage can be upgraded quickly after the changes are released:-
GitLab: gitlab!116319 (closed) -
CustomersDot: mr_url -
Status Page: mr_url
-
-
Added the ~"component:*"label(s) if applicable.
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec -
Security reports checked/validated by a reviewer from the AppSec team
Accessibility
If this MR adds or modifies a component, take a few moments to review the following:
-
All actions and functionality can be done with a keyboard. -
Links, buttons, and controls have a visible focus state. -
All content is presented in text or with a text equivalent. For example, alt text for SVG, or aria-labelfor icons that have meaning or perform actions. -
Changes in a component’s state are announced by a screen reader. For example, changing aria-expanded="false"toaria-expanded="true"when an accordion is expanded. -
Color combinations have sufficient contrast.