Skip to content

Commit e38fb5f

Browse files
authored
[ch-combo-box-render] Add support to open and select/close the ch-combo-box-render with the NumpadEnter key (#548)
This key works the same way as the Enter key
1 parent 5b331f1 commit e38fb5f

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/components/combo-box/combo-box.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ type KeyDownNoFiltersEvents =
7171
| typeof KEY_CODES.HOME
7272
| typeof KEY_CODES.END
7373
| typeof KEY_CODES.ENTER
74+
| typeof KEY_CODES.NUMPAD_ENTER
7475
| typeof KEY_CODES.SPACE
7576
| typeof KEY_CODES.TAB;
7677

7778
type KeyDownWithFiltersEvents =
7879
| typeof KEY_CODES.ARROW_UP
7980
| typeof KEY_CODES.ARROW_DOWN
8081
| typeof KEY_CODES.ENTER
82+
| typeof KEY_CODES.NUMPAD_ENTER
8183
| typeof KEY_CODES.TAB;
8284

8385
/**
@@ -231,6 +233,16 @@ export class ChComboBoxRender
231233
this.expanded = !this.expanded;
232234
},
233235

236+
// Same as the Enter handler
237+
NumpadEnter: () => {
238+
// The focus must return to the Host when closing the popover
239+
if (this.expanded) {
240+
this.#shouldFocusTheComboBox = true;
241+
}
242+
243+
this.expanded = !this.expanded;
244+
},
245+
234246
Space: event => {
235247
event.preventDefault(); // Stop space key from scrolling
236248

@@ -273,6 +285,10 @@ export class ChComboBoxRender
273285
Enter: (event: KeyboardEvent) =>
274286
this.#checkAndEmitValueChangeWithFilters(event),
275287

288+
// Same as the Enter handler
289+
NumpadEnter: (event: KeyboardEvent) =>
290+
this.#checkAndEmitValueChangeWithFilters(event),
291+
276292
Tab: (event: KeyboardEvent) =>
277293
this.#checkAndEmitValueChangeWithFilters(event)
278294
};

src/components/combo-box/tests/keyboard-selection-filters.e2e.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ const keysToConfirmClose: ConfirmKeys[] = [
392392
"Enter",
393393
// "Escape",
394394

395-
// TODO: Fix this test
396-
// "NumpadEnter",
395+
"NumpadEnter",
397396

398397
"Tab",
399398
"LeftMouseClick"

src/components/combo-box/tests/keyboard-selection.e2e.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ const keysToConfirmClose: ConfirmKeys[] = [
453453
// TODO: Fix this test
454454
// "Escape",
455455

456-
// TODO: Fix this test
457-
// "NumpadEnter",
456+
"NumpadEnter",
458457

459458
"Tab",
460459
"LeftMouseClick"

src/components/combo-box/tests/opening.e2e.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@ const SUGGEST_KEYS_TO_NOT_OPEN: KeyToPress[] = [
4343
"Tab"
4444
];
4545

46-
const COMBO_BOX_KEYS_TO_OPEN: KeyToPress[] = [
47-
"Space",
48-
"Enter"
49-
// "NumpadEnter"
50-
];
46+
const COMBO_BOX_KEYS_TO_OPEN: KeyToPress[] = ["Space", "Enter", "NumpadEnter"];
5147
const SUGGEST_KEYS_TO_OPEN: KeyToPress[] = [
5248
// TODO: Fix $0.focus() to fix these tests
5349
// "ArrowDown",
5450
// "ArrowUp",
5551
"Space",
56-
"Enter"
57-
// "NumpadEnter"
52+
"Enter",
53+
"NumpadEnter"
5854
];
5955

6056
const COMBO_BOX_KEYS_TO_NOT_CLOSE: KeyToPress[] = [
@@ -69,16 +65,16 @@ const COMBO_BOX_KEYS_TO_NOT_CLOSE: KeyToPress[] = [
6965
const COMBO_BOX_KEYS_TO_CLOSE: KeyToPress[] = [
7066
"Enter",
7167
"Escape",
72-
// "NumpadEnter",
68+
"NumpadEnter",
7369
"Tab"
7470
];
7571

7672
const COMBO_BOX_KEYS_TO_CLOSE_AND_RETURN_FOCUS: KeyToPress[] = [
7773
// TODO: Fix these tests
7874
"Enter",
7975
"Escape",
80-
"Tab"
81-
// "NumpadEnter"
76+
"Tab",
77+
"NumpadEnter"
8278
];
8379

8480
const STRICT_FILTERS: ComboBoxSuggestOptions = { strict: true };

0 commit comments

Comments
 (0)