swarm ui: a command menu above an agent's message box
This commit is contained in:
parent
49719842b0
commit
fc650f6af3
1 changed files with 478 additions and 12 deletions
|
|
@ -24,6 +24,8 @@ export function TextField({
|
|||
placeholder,
|
||||
hideLabel,
|
||||
suggestions,
|
||||
onKeyDown,
|
||||
combobox,
|
||||
}: {
|
||||
id: string;
|
||||
label: string;
|
||||
|
|
@ -39,6 +41,16 @@ export function TextField({
|
|||
/** Values to pick from. The field stays free text: a value that is not in
|
||||
* the list can still be typed. */
|
||||
suggestions?: TextFieldSuggestion[];
|
||||
/** Key presses in the field, for a caller that draws its own menu. */
|
||||
onKeyDown?: (e: KeyboardEvent) => void;
|
||||
/** Marks the field as the text box of a menu the caller draws itself. */
|
||||
combobox?: {
|
||||
expanded: boolean;
|
||||
/** The id of the menu's list. */
|
||||
controls: string;
|
||||
/** The id of the selected row, when there is one. */
|
||||
activeDescendant?: string;
|
||||
};
|
||||
}) {
|
||||
const listId = `${id}-suggestions`;
|
||||
return (
|
||||
|
|
@ -56,6 +68,13 @@ export function TextField({
|
|||
required={required}
|
||||
placeholder={placeholder}
|
||||
list={suggestions ? listId : undefined}
|
||||
autoComplete={combobox ? "off" : undefined}
|
||||
role={combobox ? "combobox" : undefined}
|
||||
aria-expanded={combobox ? combobox.expanded : undefined}
|
||||
aria-controls={combobox ? combobox.controls : undefined}
|
||||
aria-activedescendant={combobox?.activeDescendant}
|
||||
aria-autocomplete={combobox ? "list" : undefined}
|
||||
onKeyDown={onKeyDown}
|
||||
onInput={(e) => onInput((e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
{suggestions ? (
|
||||
|
|
|
|||
Loading…
Reference in a new issue