A small PR in an Angular application with a profile public identifier selection form needs to be reviewed.
Stack and environment:
- Angular 20.0.0, standalone components
- TypeScript 5.8
- RxJS 7.8
- ChangeDetectionStrategy.OnPush
- zoned application with standard Zone.js
- Reactive Forms
- Runs in the browser, without SSR
Functional requirements of the component:
- The
handle field accepts user input.
- After entering 2 characters, suggestions from the
HandleApi.search(term) API are shown.
- While the request is in flight, the text
Поиск... must be displayed.
- If the field contains only spaces, no request must be sent and the suggestions must be cleared.
- Submitting the form is allowed only after selecting one of the suggestions, not after arbitrary manual input.
- After selecting a suggestion with a button or keyboard, the form must preserve the selected
id, while the field must keep the label.
- If the text is later changed manually, the previously selected option must become invalid.
- When the component is destroyed, there must be no active subscriptions left.
API contract in this task:
search(term: string): Observable<HandleOption[]>
HandleOption = { id: string; label: string }
- The method returns results with an artificial delay of 120 ms.
- For
term === 'taken', the API returns one element { id: '7', label: 'taken_team' }.
- For other non-empty queries of at least 2 characters, the API returns up to two elements starting with the entered string.
How to reproduce the observed behavior after the PR:
- Open the form.
- Enter
ta, wait for the suggestions.
- Without selecting a suggestion, type additional arbitrary text and notice that the form is already considered valid and the button can be clicked.
- Select a suggestion, then manually change the text in the field to something else — the form may still remain submittable with the previous selected value.
- Quickly enter different values several times and then remove the component from the page: in the review, the subscription lifecycle and the consequences for
OnPush state must be checked separately.
Assumptions:
- The template should remain keyboard accessible through standard controls.
- Network errors are not modeled in this scenario.
- The task is to assess regressions in the PR, not to rewrite the solution from scratch.