Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Input with DataList never shows dropdown after its 1st closing #9881

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

nsbarsukov
Copy link
Member

@nsbarsukov nsbarsukov commented Dec 2, 2024

Fixes #9666

Reproduction 1

  1. Open https://taiga-ui.dev/v3
  2. Focus search textfield
  3. Enter acc
  4. Press Backspace
  5. Type c again

Expected behavior: dropdown is shown
Actual behavior: you will never see dropdown again

Reproduction 2

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';

@Component({
  selector: `my-app`,
  template: `
    <tui-root>
      <tui-input [formControl]="control">
        Enter 3 characters

        <ng-container *ngIf="control.value.length > 2">
          <tui-data-list *tuiDataList> Blah blah </tui-data-list>
        </ng-container>
      </tui-input>
    </tui-root>
  `,
})
export class AppComponent {
  readonly control = new FormControl('');
}
  1. Enter any 3 characters
  2. Press Backspace
  3. Insert any number of additional characters

Expected behavior: dropdown is shown
Actual behavior: you will never see dropdown again

Explore more:
https://stackblitz.com/edit/input-with-datalist-v3-bug?file=src%2Fapp%2Fapp.component.ts



Why bug happens ?

Everything starts from here:

<tui-hosted-dropdown
class="t-hosted"
[canOpen]="canOpen"
[content]="datalist || ''"
[(open)]="open"

onValueChange(value: string): void {
this.value = value;
this.open = true;

It means that every keystroke opens dropdown.
This method decides should it can it be opened or not

get canOpen(): boolean {
return this.interactive && !!this.datalist;

Then props drilling finishes here:

[tuiDropdownManual]="isOpen && canOpen"
[tuiDropdownOpenMonitor]="isOpen && canOpen"

set tuiDropdownOpenMonitor(open: boolean) {
this.open?.update(open);
this.hosted.updateOpen(open);

DropdownOpenMonitor should not update its host (host is controlled outside inside HostedDropdown codebase).
DropdownOpenMonitor should only update external DropdownOpen (if host decides to close dropdown) or vice versa.

Are there any other solutions ?
We could listen to openChange here and call this.cdr.detectChanges on any UPSTREAM data-flow ([open] should be recalculated after view updates are already finished).

It is dangerous solution because it can cause ExpressionChangedAfterItHasBeenCheckedError.

@nsbarsukov nsbarsukov self-assigned this Dec 2, 2024
Copy link

lumberjack-bot bot commented Dec 2, 2024

Pull request was closed ✔️

All saved screenshots (for current PR) were deleted 🗑️

@github-actions github-actions bot added the v3 label Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

Visit the preview URL for this PR (updated for commit 51d0683):

https://taiga-ui--pr9881-fix-doc-search-bawbhf8l.web.app

(expires Tue, 03 Dec 2024 12:07:44 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4b5ece1e114386f6a105425ef799091475b249eb

Copy link

bundlemon bot commented Dec 2, 2024

BundleMon

Files updated (1)
Status Path Size Limits
demo/browser/runtime.(hash).js
42.07KB (+25B +0.06%) +10%
Unchanged files (4)
Status Path Size Limits
demo/browser/main.(hash).js
397.73KB +10%
demo/browser/vendor.(hash).js
214.53KB +10%
demo/browser/polyfills.(hash).js
15.2KB +10%
demo/browser/styles.(hash).css
1.39KB +10%

Total files change +35B +0.01%

Groups updated (1)
Status Path Size Limits
demo/browser/*..js
2.46MB (+2.05KB +0.08%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@nsbarsukov nsbarsukov marked this pull request as ready for review December 2, 2024 11:55
@nsbarsukov nsbarsukov changed the title fix(kit): Input with DataList never shows dropdown after its 1st closing fix(core): Input with DataList never shows dropdown after its 1st closing Dec 2, 2024
@nsbarsukov nsbarsukov merged commit eb71369 into v3.x Dec 3, 2024
33 of 34 checks passed
@nsbarsukov nsbarsukov deleted the fix-doc-search branch December 3, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants