|
| 1 | +## Component Decision Tree |
| 2 | + |
| 3 | +If the user does not specify which component they would like to use, choose one based on the requirements. Use the following as a guide: |
| 4 | + |
| 5 | +- Prefer an existing React Spectrum S2 component over a custom component. |
| 6 | +- Match the interaction model first, then the visual treatment. |
| 7 | +- Prefer the narrowest component that fits the requirement instead of a more general one. |
| 8 | +- If two components could work, choose the more standard and accessible pattern. |
| 9 | +- Reach for React Aria Components plus the S2 `style` macro only as a last resort when no S2 component fits the behavior or layout, or if the user specifically asks for a custom component. |
| 10 | + |
| 11 | +### Actions and navigation |
| 12 | + |
| 13 | +- Use `Button` for primary or secondary calls to action and prominent actions. It can also navigate. |
| 14 | +- Use `ActionButton` for lower-emphasis actions, toolbar actions, row actions, and compact icon-led actions. |
| 15 | +- Use `LinkButton` when the element should navigate like a link but look like a button. |
| 16 | +- Use `Link` for inline or standalone text navigation. |
| 17 | +- Use `ButtonGroup` or `ActionButtonGroup` only to group related buttons. |
| 18 | +- Use `ActionMenu` for a simple "more actions" ellipsis button that opens a menu. |
| 19 | +- Use `Menu` when the menu itself is the pattern, especially if you need sections, submenus, selection, links, or a custom trigger arrangement. |
| 20 | +- Use `ActionBar` for bulk actions within a collection component. |
| 21 | + |
| 22 | +### Choosing from options |
| 23 | + |
| 24 | +- Use `Switch` for turning a setting on or off. |
| 25 | +- Use `Checkbox` for a single independent yes or no option. |
| 26 | +- Use `CheckboxGroup` for multiple simple visible options where many may be selected. |
| 27 | +- Use `RadioGroup` for a small visible mutually exclusive list. |
| 28 | +- Use `SelectBoxGroup` when options should stay visible and need richer presentation such as illustrations, labels, or descriptions. |
| 29 | +- Use `Picker` for selecting from a collapsible list of known options when typing to search is not important. |
| 30 | +- Use `ComboBox` when the user should type to filter options, search a long list, or create an action from the current input. |
| 31 | +- Use `SegmentedControl` for a small mutually exclusive view or mode switch. |
| 32 | +- Use `ToggleButton` for a single pressed/unpressed control. |
| 33 | +- Use `ToggleButtonGroup` for compact formatting-style or tool-style toggles, especially if multi-select may be needed. |
| 34 | + |
| 35 | +### Text and value input |
| 36 | + |
| 37 | +- Use `TextField` for single-line plain text input. |
| 38 | +- Use `SearchField` for a search query with search-specific clear and submit behavior. |
| 39 | +- Use `TextArea` for multi-line text. |
| 40 | +- Use `NumberField` for precise numeric entry and stepping. |
| 41 | +- Use `Slider` for adjusting one numeric value when direct manipulation is more important than exact typed entry. |
| 42 | +- Use `RangeSlider` for adjusting a numeric range. |
| 43 | +- Use `DateField` or `TimeField` when keyboard editing of a date or time is the main interaction. |
| 44 | +- Use `DatePicker` or `DateRangePicker` when a popover calendar should help with choosing dates. |
| 45 | +- Use `Calendar` or `RangeCalendar` when the calendar grid itself is needed without the input field or popover. |
| 46 | +- Use `ColorField` to edit a hex color or channel value directly. |
| 47 | +- Use `ColorSwatch` to display a chosen color. |
| 48 | +- Use `ColorSwatchPicker` to choose from predefined colors. |
| 49 | +- Use `ColorArea`, `ColorSlider`, and `ColorWheel` for direct color manipulation. |
| 50 | + |
| 51 | +### Collections and data views |
| 52 | + |
| 53 | +- Use `TableView` when users need rows and columns, dense comparison, sortable headers, cell-level content, editable cells, column resizing, or other tabular behaviors. |
| 54 | +- Use `ListView` for a flat list of records where each row is the main unit and may include icons, thumbnails, descriptions, and row actions. |
| 55 | +- Use `TreeView` when the hierarchy itself must stay visible and expandable in place. |
| 56 | +- Use `CardView` for visually rich collections of objects, galleries, or asset browsers with selection and bulk actions. |
| 57 | +- Use `TagGroup` for compact tags, tokens, or filters rather than general records. |
| 58 | +- Use `TableView` with expandable rows only if the tabular columns still matter after hierarchy is introduced. |
| 59 | +- Use `ListView` with `hasChildItems` and breadcrumbs for drill-in navigation when only one level is shown at a time. |
| 60 | + |
| 61 | +### `TableView` vs `ListView` vs `TreeView` vs `CardView` |
| 62 | + |
| 63 | +- Choose `TableView` if the user needs to compare fields across columns. |
| 64 | +- Choose `ListView` if the user needs a simple vertical list of records with optional secondary content and actions. |
| 65 | +- Choose `TreeView` if parent-child structure is the key mental model. |
| 66 | +- Choose `CardView` if preview imagery, card layouts, or gallery browsing matter more than dense comparison. |
| 67 | + |
| 68 | +### Cards |
| 69 | + |
| 70 | +- Use `Card` for one summarized object, not for an entire selectable collection. |
| 71 | +- Use `CardView` when many cards need keyboard navigation, selection, loading states, empty states, or bulk actions. |
| 72 | +- Prefer `AssetCard` for files, images, folders, documents, or other assets. |
| 73 | +- Prefer `UserCard` for people or profiles. |
| 74 | +- Prefer `ProductCard` for products or offers with a clear call to action. |
| 75 | +- Use `Card` with `CollectionCardPreview` for grouped assets or a preview collage. |
| 76 | +- Use a preview-only `Card` for gallery tiles in a waterfall-style presentation. |
| 77 | +- Use a custom `Card` only when the object is still clearly a card but the built-in layouts do not fit the content structure. |
| 78 | + |
| 79 | +### Structure and disclosure |
| 80 | + |
| 81 | +- Use `Tabs` when switching between peer sections of content and showing one panel at a time. |
| 82 | +- Use `SegmentedControl` instead of `Tabs` when switching app modes or views rather than full content panels. |
| 83 | +- Use `Disclosure` for one collapsible section. |
| 84 | +- Use `Accordion` for a group of related collapsible sections. |
| 85 | +- Use `Breadcrumbs` to show navigation depth or hierarchy location. |
| 86 | +- Use `Divider` to separate adjacent groups of content. |
| 87 | + |
| 88 | +### Overlays, help, and feedback |
| 89 | + |
| 90 | +- Use `Tooltip` for a short description of a focusable element. Do not rely on it for essential content. |
| 91 | +- Use `ContextualHelp` for additional explanation near content, especially for non-interactive or disabled UI. |
| 92 | +- Use `Popover` for interactive contextual content anchored to a nearby trigger when a modal is unnecessary. |
| 93 | +- Use `Dialog` for modal tasks or workflows. |
| 94 | +- Use `AlertDialog` for confirmations, destructive actions, and critical messages that must be acknowledged. |
| 95 | +- Use `FullscreenDialog` for complex workflows that need substantially more space. |
| 96 | +- Use `CustomDialog` only when the standard dialog layouts do not fit. |
| 97 | +- Use `InlineAlert` for a persistent non-modal message associated with content in the current view. |
| 98 | +- Use `Toast` for temporary global feedback after an action. |
| 99 | + |
| 100 | +### Status, loading, media, and empty states |
| 101 | + |
| 102 | +- Use `Badge` for compact color-coded metadata. |
| 103 | +- Use `StatusLight` for an object's current status. |
| 104 | +- Use `ProgressBar` or `ProgressCircle` for task progress over time. |
| 105 | +- Use `Meter` for a level or quantity within a known range when it is not task progress. |
| 106 | +- Use `Skeleton` for loading placeholders. |
| 107 | +- Use `Avatar` or `AvatarGroup` for people and participants. |
| 108 | +- Use `Image` for images that need loading and error handling. |
| 109 | +- Use `IllustratedMessage` for empty states or error pages. |
| 110 | +- Use `DropZone` for drag-and-drop file or object upload targets. |
| 111 | +- Use `Form` to provide layout, submission, and validation structure for grouped fields. |
| 112 | + |
| 113 | +### Last-resort custom components |
| 114 | + |
| 115 | +- Only create a custom component when no S2 component matches the required interaction pattern, or when the needed layout cannot be achieved by composing existing S2 components. |
| 116 | +- Build custom components with React Aria Components for behavior and accessibility, and the S2 `style` macro for Spectrum styling. |
| 117 | +- Do not bypass an existing S2 component just to apply unsupported visual customization. |
0 commit comments