Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add more Autocomplete examples #7827

Merged
merged 8 commits into from
Feb 26, 2025
Merged

docs: Add more Autocomplete examples #7827

merged 8 commits into from
Feb 26, 2025

Conversation

devongovett
Copy link
Member

Adds a styled Searchable Select example. Also adds an async loading example to the docs, and added renderEmptyState to menu to support this. Removed the "State" example because the clear button is already in the search field so didn't seem necessary.

Updated text of the features section to specifically mention some of the UI patterns that can be built with Autocomplete, and tried to describe the difference with ComboBox.

@@ -487,14 +488,19 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {
focusSafely(ref.current);
}

// Wait until the collection has items to autofocus.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we delayed rendering the menu until the collection had items, but we can't do this anymore now that we have empty state support. Instead, delay auto focusing until the collection is filled.

@rspbot
Copy link

rspbot commented Feb 25, 2025

@rspbot
Copy link

rspbot commented Feb 25, 2025

@rspbot
Copy link

rspbot commented Feb 25, 2025

## API Changes

react-aria-components

/react-aria-components:Menu

 Menu <T extends {}> {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children?: ReactNode | ({}) => ReactNode
-  className?: string
+  className?: string | ((MenuRenderProps & {
+    defaultClassName: string | undefined
+})) => string
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
+  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   slot?: string | null
-  style?: CSSProperties
+  style?: CSSProperties | ((MenuRenderProps & {
+    defaultStyle: CSSProperties
+})) => CSSProperties | undefined
 }

/react-aria-components:MenuProps

 MenuProps <T> {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children?: ReactNode | (T) => ReactNode
-  className?: string
+  className?: string | ((MenuRenderProps & {
+    defaultClassName: string | undefined
+})) => string
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
+  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   slot?: string | null
-  style?: CSSProperties
+  style?: CSSProperties | ((MenuRenderProps & {
+    defaultStyle: CSSProperties
+})) => CSSProperties | undefined
 }

@react-spectrum/s2

/@react-spectrum/s2:Menu

 Menu <T extends {}> {
   UNSAFE_className?: string
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | ({}) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   hideLinkOutIcon?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
+  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   size?: 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

/@react-spectrum/s2:MenuProps

 MenuProps <T> {
   UNSAFE_className?: string
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | (T) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   hideLinkOutIcon?: boolean
   id?: string
   items?: Iterable<T>
   onAction?: (Key) => void
   onClose?: () => void
   onScroll?: (UIEvent<Element>) => void
   onSelectionChange?: (Selection) => void
+  renderEmptyState?: () => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionMode?: SelectionMode
   shouldFocusWrap?: boolean
   size?: 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

@devongovett
Copy link
Member Author

Do we want to expose renderEmptyState to S2? Seems ok but idk if design has anything specific they'd want

<XIcon aria-hidden className="w-4 h-4" />
</Button>
</SearchField>
<ListBox items={languages} className="outline-hidden p-1 overflow-auto flex-1 scroll-pb-1">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add renderEmptyState to the two examples?

@snowystinger
Copy link
Member

snowystinger commented Feb 25, 2025

Do we want to expose renderEmptyState to S2? Seems ok but idk if design has anything specific they'd want

Seems like a good idea, though we could also add it later if we're unsure right

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devongovett
Copy link
Member Author

Do we want a card for Autocomplete at the bottom here with the other components?

eventually yes. maybe once it is GA? we don't have the card for the home pages yet which is usually what we use here

@devongovett devongovett added this pull request to the merge queue Feb 26, 2025
Merged via the queue into main with commit 728d4a5 Feb 26, 2025
30 checks passed
@devongovett devongovett deleted the autocomplete-example branch February 26, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants