Skip to content

Commit

Permalink
fix: use paste event to open popover in fd-combobox (#11565)
Browse files Browse the repository at this point in the history
* fix(core): open combobox on paste event

* fix: use string instead of ClipboardEvent due to browser incompatibility

* fix: build

---------

Co-authored-by: deno <mladen.droshev@sap.com>
  • Loading branch information
mikerodonnell89 and droshev committed Mar 25, 2024
1 parent dbdaa51 commit 3511002
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions libs/core/src/lib/combobox/combobox.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
[(ngModel)]="inputText"
(onComplete)="handleAutoComplete($event)"
(keydown)="onInputKeydownHandler($event)"
(paste)="onInputKeydownHandler('pasteEvent')"
(ngModelChange)="handleSearchTermChange()"
(blur)="handleBlur()"
/>
Expand Down
72 changes: 39 additions & 33 deletions libs/core/src/lib/combobox/combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,46 +438,52 @@ export class ComboboxComponent
}

/** @hidden */
onInputKeydownHandler(event: KeyboardEvent): void {
onInputKeydownHandler(event: KeyboardEvent | string): void {
if (this.readOnly) {
return;
}

if (KeyUtil.isKeyCode(event, TAB) && this.open) {
this._close();
return;
}

if (KeyUtil.isKeyCode(event, ENTER)) {
if (this.searchFn) {
this.searchFn();
}
} else if (KeyUtil.isKeyCode(event, DOWN_ARROW)) {
if (event.altKey) {
this._resetDisplayedValues();
if (typeof event === 'string') {
if (event === 'pasteEvent') {
this.isOpenChangeHandle(true);
}
if (this.open && this.listComponent) {
this.listComponent.setItemActive(0);
} else if (!this.open) {
this._chooseOtherItem(1);
} else {
if (KeyUtil.isKeyCode(event, TAB) && this.open) {
this._close();
return;
}
event.preventDefault();
} else if (KeyUtil.isKeyCode(event, UP_ARROW)) {
this._chooseOtherItem(-1);
event.preventDefault();
} else if (KeyUtil.isKeyCode(event, this.closingKeys)) {
this.isOpenChangeHandle(false);
event.stopPropagation();
} else if (
this.openOnKeyboardEvent &&
!event.ctrlKey &&
!event.altKey &&
!KeyUtil.isKeyCode(event, this.nonOpeningKeys)
) {
this.isOpenChangeHandle(true);
if (this.isEmptyValue && KeyUtil.isKeyType(event, 'control') && !KeyUtil.isKeyCode(event, BACKSPACE)) {
this.listComponent.setItemActive(0);

if (KeyUtil.isKeyCode(event, ENTER)) {
if (this.searchFn) {
this.searchFn();
}
} else if (KeyUtil.isKeyCode(event, DOWN_ARROW)) {
if (event.altKey) {
this._resetDisplayedValues();
this.isOpenChangeHandle(true);
}
if (this.open && this.listComponent) {
this.listComponent.setItemActive(0);
} else if (!this.open) {
this._chooseOtherItem(1);
}
event.preventDefault();
} else if (KeyUtil.isKeyCode(event, UP_ARROW)) {
this._chooseOtherItem(-1);
event.preventDefault();
} else if (KeyUtil.isKeyCode(event, this.closingKeys)) {
this.isOpenChangeHandle(false);
event.stopPropagation();
} else if (
this.openOnKeyboardEvent &&
!event.ctrlKey &&
!event.altKey &&
!KeyUtil.isKeyCode(event, this.nonOpeningKeys)
) {
this.isOpenChangeHandle(true);
if (this.isEmptyValue && KeyUtil.isKeyType(event, 'control') && !KeyUtil.isKeyCode(event, BACKSPACE)) {
this.listComponent.setItemActive(0);
}
}
}
}
Expand Down

0 comments on commit 3511002

Please sign in to comment.