Document tree combobox
A searchable selector that lets people pick one document from nested folders, with metadata and a responsive selected path.
Open the field, type to search or use the arrow keys to move through folders. Only documents can be selected. Folders open and close.
When to use
- To pick one document from a collection grouped in folders, such as autos, subsídios and contracts.
- When people recognize a document by its folder or file name, so the path helps.
- When the list is too long for a flat Select.
When not to use
- A flat list. Use a Combobox or a Select.
- Choosing several documents. Use the multiple selector.
- Browsing a hierarchy with actions on each node. Use a Tree view.
States
Selected path
With showSelectedPath the trigger shows the whole path when it fits and
shortens it from the left when the field is narrow. The leaf is always visible.
Disabled
Examples
Metadata and a pinned shortcut
A node can carry a description and details. Both are searchable and are
announced to screen readers. separatorAfter draws a divider below a pinned
node.
Content
ariaLabelnames the field and the tree: “Documento de referência”.placeholdersays what to pick: “Selecione um documento”.emptyMessageexplains the empty search: “Nenhum documento encontrado.”- Use the file name as
descriptionwhen labels repeat across folders. - Pass every string from the app. The component has no built-in copy.
Accessibility
- The trigger is a button with
role="combobox",aria-haspopup="tree",aria-expandedandaria-controls. Its name combinesariaLabeland the selected path. - The list is a WAI-ARIA tree:
role="tree"androle="treeitem"witharia-level,aria-posinset,aria-setsizeandaria-expandedon folders. Documents setaria-selected. ArrowDownandArrowUpmove between visible nodes.HomeandEndgo to the first and last.ArrowRightopens a folder or enters it,ArrowLeftcloses it or goes to the parent.EnterorSpaceselects a document or toggles a folder.- Focus moves to the search input when the popover opens.
ArrowDownin the search moves into the tree. Typing a character in the tree sends it to the search. - While searching, folders with matches stay open and matching text is highlighted.
The empty message has
role="status". - Matching ignores accents and case.
Code
import { DocumentTreeCombobox } from "@repo/ui/document-tree-combobox";
import type { DocumentTreeComboboxNode } from "@repo/ui/document-tree-combobox";
const nodes: DocumentTreeComboboxNode[] = [
{
children: [
{
description: "contestacao.pdf",
id: "contestacao",
label: "Contestação",
value: "contestacao",
},
],
id: "autos",
label: "Autos do processo",
},
];
<DocumentTreeCombobox
ariaLabel="Documento de referência"
emptyMessage="Nenhum documento encontrado."
name="documento"
nodes={nodes}
onValueChange={setValue}
placeholder="Selecione um documento"
searchPlaceholder="Buscar documento"
value={value}
/>;
Props
DocumentTreeCombobox| Prop | Type | Default | Description |
|---|---|---|---|
ariaLabel | string | — | Accessible name of the trigger and the tree |
disabled | boolean | false | Prevents opening and changing the selection |
emptyMessage | string | — | Message shown when no node matches the search |
name | string | — | Name of the hidden input used for form submission |
placeholder | string | — | Text of the trigger when nothing is selected |
searchPlaceholder | string | — | Placeholder and accessible name of the search input |
showSelectedPath | boolean | false | Shows the selected path in the trigger when it fits; otherwise shows only the leaf |
More props| Prop | Type | Default | Description |
|---|---|---|---|
nodes | DocumentTreeComboboxNode[] | — | Folders and documents. The component renders nothing when the list is empty. |
value | string | — | Selected document value, when the caller controls it. |
defaultValue | string | "" | Initial value when the component keeps its own state. |
onValueChange | (value: string) => void | — | Called when a document is selected. |
className | string | — | Layout classes for the trigger. |
listClassName | string | — | Layout classes for the scrollable tree. |
ref | Ref<HTMLButtonElement> | — | Ref of the trigger. |
DocumentTreeComboboxNode| Prop | Type | Default | Description |
|---|---|---|---|
id | string | — | Unique identifier of the node. |
label | string | — | Searchable name of the folder or document. |
value | string | — | Value of a selectable document. Folders have none. |
children | DocumentTreeComboboxNode[] | — | Nested nodes. A node with children is a folder. |
displayLabel | string | — | Shorter label shown in the tree and the trigger. |
description | string | — | Secondary searchable text, such as the file name. |
details | { label: string; value: string }[] | — | Searchable metadata shown under the label. |
icon | ReactNode | — | Decorative icon shown before a document label. |
searchText | string | — | Hidden aliases used only by the search. |
separatorAfter | boolean | — | Draws a divider below the node unless it is the last in its list. |
Known issues
| Issue | Effect |
|---|---|
Rows use hover:bg-disabled for the hover state. |
A disabled-state token styles an interactive hover, which can look unavailable. |
The trigger caret uses opacity-50. |
Opacity lowers the icon contrast. |
Rows have a min-h-8 (32px) height with no touch variant. |
Meets the 24px desktop minimum, but is small on touch screens. |
A node with value set and children is a folder that cannot be selected. |
Easy to configure by mistake: the value is silently ignored. |