diff --git a/sample-app/package-lock.json b/sample-app/package-lock.json
index d9275498..51a9f3d1 100644
--- a/sample-app/package-lock.json
+++ b/sample-app/package-lock.json
@@ -89,7 +89,7 @@
},
"..": {
"name": "@yext/answers-headless-react",
- "version": "0.3.0-beta.0",
+ "version": "0.4.0-beta.0",
"dependencies": {
"@reduxjs/toolkit": "^1.6.2",
"@types/react": "^17.0.15",
diff --git a/sample-app/src/components/Dropdown.tsx b/sample-app/src/components/Dropdown.tsx
index 5f00dba2..aec7e68e 100644
--- a/sample-app/src/components/Dropdown.tsx
+++ b/sample-app/src/components/Dropdown.tsx
@@ -30,7 +30,11 @@ export default function Dropdown({
[cssClasses.focusedOption]: index === focusedOptionIndex
})
return (
-
onClickOption(option)}>
+
onClickOption(option)}>
{option.render()}
)
}
diff --git a/sample-app/src/components/InputDropdown.tsx b/sample-app/src/components/InputDropdown.tsx
index 8fc020ad..da4d8ca6 100644
--- a/sample-app/src/components/InputDropdown.tsx
+++ b/sample-app/src/components/InputDropdown.tsx
@@ -59,6 +59,9 @@ export default function InputDropdown({
focusedOptionIndex: undefined,
shouldDisplayDropdown: false,
});
+ const focusOptionId = focusedOptionIndex === undefined
+ ? undefined
+ : `${cssClasses.option}-${focusedOptionIndex}`;
const [latestUserInput, setLatestUserInput] = useState(inputValue);
@@ -83,12 +86,11 @@ export default function InputDropdown({
const isFirstOptionFocused = focusedOptionIndex === 0;
const isLastOptionFocused = focusedOptionIndex === options.length - 1;
-
if (evt.key === 'Enter') {
updateInputValue(inputValue);
onSubmit(inputValue);
dispatch({ type: 'HideOptions' });
- } else if (evt.key === 'Escape') {
+ } else if (evt.key === 'Escape' || evt.key === 'Tab') {
dispatch({ type: 'HideOptions' });
} else if (evt.key === 'ArrowDown' && options.length > 0 && !isLastOptionFocused) {
const newIndex = focusedOptionIndex !== undefined ? focusedOptionIndex + 1 : 0;
@@ -125,6 +127,7 @@ export default function InputDropdown({
onKeyDown={onKeyDown}
value={inputValue}
ref={inputRef}
+ aria-activedescendant={focusOptionId}
/>
{renderButtons()}