Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[(value)]="searchString"
[(expanded)]="popupExpanded"
(click)="popupExpanded.set(true)"
(keydown.escape)="!popupExpanded() && !$event.defaultPrevented && searchString.set('')"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the defaultPrevented check? I'm not sure we're preventing it anywhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/angular/components/blob/main/src/aria/private/combobox/combobox.ts#L140 the combobox handles the escape key and prevents default, without the defaultPrevented the input box will be cleared even when the popup is opened (the clear behavior should only happen when the popup is closed and escape hit is hit)... popupExpanded() returns false immediately once the escape key is hit, so we can't rely on that value.

Maybe the clear behavior needs to be baked into the combobox pattern... Let me take a further look.

/>
<button
class="example-clear-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined" />
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined"
(keydown.escape)="!popupExpanded() && !$event.defaultPrevented && searchString.set('')" />
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div #origin class="example-autocomplete">
<span class="example-search-icon material-symbols-outlined" translate="no">search</span>
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
(keydown.escape)="!popupExpanded() && !$event.defaultPrevented && searchString.set('')" />
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
</button>
Expand Down
Loading