gitlab-ui: allow clearing search input from GlCollapsibleListbox when dropdown closes (follow-up to !214026)

Summary

  • The Custom Agent Selector (MR gitlab-org/gitlab!214026 (merged)) relies on reaching into the component VM to clear the search input when the dropdown closes. We need a proper API in gitlab-ui's GlCollapsibleListbox / search input so consumers can clear the input without touching internal refs.

Problem

  • Current workaround calls this.$refs.customAgentSelector.$refs.searchBox?.clearInput() from the consumer, which breaks component encapsulation and is brittle (see discussion: gitlab-org/gitlab!214026 (comment 2936080166)).
  • This makes tests brittle and risks regressions if internals change.

Proposed solution

  1. Add a public API/event to GlCollapsibleListbox (or the search box subcomponent) to clear/reset the search input. Options:
    • Expose a method on the component instance (e.g. clearInput()) documented as public, or
    • Emit a well-defined event (e.g. 'clear-search') consumers can trigger/handle, or
    • On dropdown hidden event, ensure internal search input is reset automatically (configurable behavior).
  2. Update gitlab-org/gitlab consumers (e.g. Custom Agent Selector) to use the new API instead of accessing $refs.
  3. Add unit tests in gitlab-ui to cover the API and integration tests in gitlab to remove fragile vm-based assertions.
  4. Add a migration note / small guide for consumers that currently rely on internal refs.

Acceptance criteria

  • gitlab-ui component exposes a documented API to clear the search input or automatically clears it when closed.
  • Consumers no longer access internal $refs to clear the input.
  • Tests updated to use public API and pass in Vue3 spec suite.

References

Edited by 🤖 GitLab Bot 🤖