Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
6 changes: 3 additions & 3 deletions packages/usa-combo-box/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ const handleDownFromListOption = (event) => {
};

/**
* Handle the tab event from an list option element within the combo box component.
* Handle the space event from an list option element within the combo box component.
*
* @param {KeyboardEvent} event An event within the combo box component
*/
const handleTabFromListOption = (event) => {
const handleSpaceFromListOption = (event) => {
selectItem(event.target);
event.preventDefault();
};
Expand Down Expand Up @@ -779,7 +779,7 @@ const comboBox = behavior(
ArrowDown: handleDownFromListOption,
Down: handleDownFromListOption,
Enter: handleEnterFromListOption,
Tab: handleTabFromListOption,
" ": handleSpaceFromListOption,
"Shift+Tab": noop,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/usa-combo-box/src/test/combo-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ tests.forEach(({name, selector: containerSelector}) => {
);
});

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

EVENTS.keydownTab(focusedOption);
EVENTS.keydownSpace(focusedOption);

assert.strictEqual(
select.value,
Expand Down
12 changes: 12 additions & 0 deletions packages/usa-combo-box/src/test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ EVENTS.keydownTab = (el) => {
el.dispatchEvent(evt);
};

/**
* send a keydown Space event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keydownSpace = (el) => {
const evt = new KeyboardEvent("keydown", {
bubbles: true,
key: " ",
});
el.dispatchEvent(evt);
};

/**
* send a keydown ArrowDown event
* @param {HTMLElement} el the element to sent the event to
Expand Down