Visitar URL original
Merge pull request #5160 from uswds/cm-combobox-tab-space-fix · uswds/uswds@b854664 · GitHub
Skip to content

Commit b854664

Browse files
authored
Merge pull request #5160 from uswds/cm-combobox-tab-space-fix
USWDS - Combobox: Keyboard selection compliance update. Resolves #5161
2 parents f39d0af + 792d867 commit b854664

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/usa-combo-box/src/index.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,11 @@ const handleDownFromListOption = (event) => {
646646
};
647647

648648
/**
649-
* Handle the tab event from an list option element within the combo box component.
649+
* Handle the space event from an list option element within the combo box component.
650650
*
651651
* @param {KeyboardEvent} event An event within the combo box component
652652
*/
653-
const handleTabFromListOption = (event) => {
653+
const handleSpaceFromListOption = (event) => {
654654
selectItem(event.target);
655655
event.preventDefault();
656656
};
@@ -779,7 +779,7 @@ const comboBox = behavior(
779779
ArrowDown: handleDownFromListOption,
780780
Down: handleDownFromListOption,
781781
Enter: handleEnterFromListOption,
782-
Tab: handleTabFromListOption,
782+
" ": handleSpaceFromListOption,
783783
"Shift+Tab": noop,
784784
}),
785785
},

‎packages/usa-combo-box/src/test/combo-box.spec.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ tests.forEach(({ name, selector: containerSelector }) => {
408408
);
409409
});
410410

411-
it("should select the focused list item in the list when pressing tab on a focused item", () => {
411+
it("should select the focused list item in the list when pressing space on a focused item", () => {
412412
select.value = "cantaloupe";
413413
input.value = "berry";
414414
EVENTS.input(input);
@@ -420,7 +420,7 @@ tests.forEach(({ name, selector: containerSelector }) => {
420420
"should focus the first item in the list"
421421
);
422422

423-
EVENTS.keydownTab(focusedOption);
423+
EVENTS.keydownSpace(focusedOption);
424424

425425
assert.strictEqual(
426426
select.value,

‎packages/usa-combo-box/src/test/events.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ EVENTS.keydownTab = (el) => {
6868
el.dispatchEvent(evt);
6969
};
7070

71+
/**
72+
* send a keydown Space event
73+
* @param {HTMLElement} el the element to sent the event to
74+
*/
75+
EVENTS.keydownSpace = (el) => {
76+
const evt = new KeyboardEvent("keydown", {
77+
bubbles: true,
78+
key: " ",
79+
});
80+
el.dispatchEvent(evt);
81+
};
82+
7183
/**
7284
* send a keydown ArrowDown event
7385
* @param {HTMLElement} el the element to sent the event to

0 commit comments

Comments
 (0)