diff --git a/src/components/TagInput.tsx b/src/components/TagInput.tsx index fa73ae15..9a682a58 100644 --- a/src/components/TagInput.tsx +++ b/src/components/TagInput.tsx @@ -6,6 +6,9 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; const KEY_KEYDOWN = 'keydown'; const CREATE_LABEL = 'Create'; +const ARIA_ID_TAG_CONTROL = 'tag-control'; +const ARIA_ID_TAG_OPTIONS = 'tag-options'; + export default function TagInput({ name, value = '', @@ -195,19 +198,35 @@ export default function TagInput({ } }} > -
+
+ {selectedOptions.length === 0 + ? 'No tags selected' + : selectedOptions.join(', ') + + ` tag${selectedOptions.length !== 1 ? 's' : ''} selected`} +
+
{selectedOptions .filter(Boolean) .map(option => setSelectedOptionIndex(undefined)} + aria-autocomplete="list" + aria-expanded={shouldShowMenu} + aria-haspopup="true" + aria-controls={shouldShowMenu ? ARIA_ID_TAG_OPTIONS : undefined} + role="combobox" />
-
-
0) && 'hidden', - 'control absolute top-0 mt-3 w-full z-10 !px-1.5 !py-1.5', - 'max-h-[8rem] overflow-y-auto', - 'flex flex-col gap-y-1', - 'text-xl shadow-lg dark:shadow-xl', - )} - > - {optionsFiltered.map(({ value, annotation }, index) => -
{ - addOption(value); - setInputText(''); - }} - onFocus={() => setSelectedOptionIndex(index)} - > - - {value} - - {annotation && - - {annotation} - } -
)} -
-
+ {shouldShowMenu && optionsFiltered.length > 0 && +
+
+ {optionsFiltered.map(({ value, annotation }, index) => +
{ + addOption(value); + setInputText(''); + }} + onFocus={() => setSelectedOptionIndex(index)} + > + + {value} + + {annotation && + + {annotation} + } +
)} +
+
}
); }