Skip to content

Commit 9b8afc7

Browse files
committed
Correct Enter key behavior in freeform mode
1 parent 891be92 commit 9b8afc7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/labs/ia-combo-box/ia-combo-box.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class IAComboBox extends LitElement {
401401
?disabled=${this.disabled}
402402
?required=${this.required}
403403
@click=${this.handleComboBoxClick}
404-
@keydown=${this.handleTextBoxKeyDown}
404+
@keydown=${this.handleComboBoxKeyDown}
405405
@input=${this.handleTextBoxInput}
406406
@focus=${this.handleFocus}
407407
@blur=${this.handleBlur}
@@ -434,6 +434,7 @@ export class IAComboBox extends LitElement {
434434
aria-expanded=${this.open}
435435
?disabled=${this.disabled}
436436
@click=${this.handleComboBoxClick}
437+
@keydown=${this.handleComboBoxKeyDown}
437438
@focus=${this.handleFocus}
438439
@blur=${this.handleBlur}
439440
>
@@ -544,7 +545,7 @@ export class IAComboBox extends LitElement {
544545
/**
545546
* Handler for `keydown` events on various special keys.
546547
*/
547-
private handleTextBoxKeyDown(e: KeyboardEvent): void {
548+
private handleComboBoxKeyDown(e: KeyboardEvent): void {
548549
switch (e.key) {
549550
case 'Enter':
550551
this.handleEnterPressed();
@@ -600,13 +601,16 @@ export class IAComboBox extends LitElement {
600601
return;
601602
}
602603

603-
// If an option is highlighted, select it
604604
if (this.highlightedOption) {
605+
// If an option is highlighted, select it
605606
this.setSelectedOption(this.highlightedOption.id);
606-
607-
// Close the options list if needed
608-
if (!this.stayOpen) this.open = false;
607+
} else if (this.behavior === 'freeform') {
608+
// Otherwise, in the freeform behavior we just accept the current value regardless
609+
this.setValue(this.enteredText);
609610
}
611+
612+
// Close the options list if needed
613+
if (!this.stayOpen) this.open = false;
610614
}
611615

612616
/**

0 commit comments

Comments
 (0)