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(Autocomplete): add RAC Autocomplete docs #7784

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

reidbarber
Copy link
Member

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Feb 19, 2025

@rspbot
Copy link

rspbot commented Feb 19, 2025

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

somehow we need to find a way to emphasize that Autocomplete works with both TextField and SearchField, and with both Menu and ListBox. Right now the examples suggest it works only with SearchField and Menu. Maybe we should mix them up a bit and provide some more varied examples that people might google for as well? Searchable menu, Command palette, Filterable Select (like the story we have), etc.

Autocomplete follows the [Collection Components API](collections.html), accepting both static and dynamic collections.
The examples above show static collections, which can be used when the full list of options is known ahead of time. Dynamic collections,
as shown below, can be used when the options come from an external data source such as an API call, or update over time.

Copy link
Member

Choose a reason for hiding this comment

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

this is really about menu/listbox rather than autocomplete itself... we may want to emphasize somehow that Autocomplete works with Menu or ListBox and this isn't specific to either one of those or autocomplete itself.

The Reusable Wrappers example also sort of suggests it requires a Menu. Not sure what the best way is to show that it works with both...

@reidbarber reidbarber changed the title [WIP] docs(Autocomplete): add RAC Autocomplete docs docs(Autocomplete): add RAC Autocomplete docs Feb 19, 2025
Copy link
Member

@yihuiliao yihuiliao left a comment

Choose a reason for hiding this comment

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

* A autocomplete combines a text input with a menu, allowing users to filter a list of options to items matching a query.

unrelated to the changes here but i noticed that the description says "a autocomplete..." instead of "an autocomplete"

@rspbot
Copy link

rspbot commented Feb 20, 2025


# Command Palette

A Command Palette is an interface that allows users to quickly run commands or navigate to content within an application. This example uses the [`Autocomplete`](../Autocomplete.html) component from React Aria Components to filter a list of commands and display them in a [`Menu`](../Menu.html). The [`TextField`](../TextField.html) is used to capture user input and filter the list of available commands.
Copy link
Member

Choose a reason for hiding this comment

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

This is a little long. Maybe create a sub-heading ## Example like some of the other example pages and put the second sentence on under that?


return (
<div className="bg-linear-to-r from-indigo-500 to-violet-500 p-8 h-[340px] rounded-lg flex flex-col items-center justify-center">
<div className="flex flex-col gap-1 w-[320px] rounded-md bg-white shadow-lg">
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to make this into a Dialog that you could open with Command K (or by clicking a button)?

<Menu /> {/* or <ListBox /> */}
</Autocomplete>
```

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add outline: none by default in SearchField.mdx to prevent the browser default focus ring from showing up (except when [data-focused])?

snowystinger
snowystinger previously approved these changes Feb 21, 2025
@rspbot
Copy link

rspbot commented Feb 21, 2025

return (
<div className="bg-linear-to-r from-indigo-500 to-violet-500 p-8 h-[340px] rounded-lg flex items-center justify-center">
{isOpen ?
<div className="flex flex-col gap-1 w-[320px] rounded-md bg-white shadow-lg">
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 use the Modal/Dialog components for this? Might be a bit more like a real implementation that way

</Menu>
</Autocomplete>
</div>
: <span className="text-white text-lg">Press <kbd>⌘</kbd> + <kbd>K</kbd> to open the command palette.</span>
Copy link
Member

Choose a reason for hiding this comment

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

We should have this be a button (with a DialogTrigger I guess) so you can also open it on touch devices

@rspbot
Copy link

rspbot commented Feb 21, 2025

@rspbot
Copy link

rspbot commented Feb 21, 2025

## API Changes

react-aria-components

/react-aria-components:UNSTABLE_Autocomplete

-UNSTABLE_Autocomplete {
-  children: ReactNode
-  defaultInputValue?: string
-  filter?: (string, string) => boolean
-  inputValue?: string
-  onInputChange?: (string) => void
-  slot?: string | null
-}

/react-aria-components:UNSTABLE_AutocompleteContext

-UNSTABLE_AutocompleteContext {
-  UNTYPED
-}

/react-aria-components:UNSTABLE_AutocompleteStateContext

-UNSTABLE_AutocompleteStateContext {
-  UNTYPED
-}

/react-aria-components:Autocomplete

+Autocomplete {
+  children: ReactNode
+  defaultInputValue?: string
+  filter?: (string, string) => boolean
+  inputValue?: string
+  onInputChange?: (string) => void
+  slot?: string | null
+}

/react-aria-components:AutocompleteContext

+AutocompleteContext {
+  UNTYPED
+}

/react-aria-components:AutocompleteStateContext

+AutocompleteStateContext {
+  UNTYPED
+}

<div className="bg-linear-to-r from-indigo-500 to-violet-500 p-8 h-[340px] rounded-lg flex items-center justify-center">
<DialogTrigger isOpen={isOpen} onOpenChange={setOpen}>
<Button className="inline-flex items-center justify-center rounded-xl bg-black/20 bg-clip-padding border border-white/20 px-3.5 py-2 font-medium font-[inherit] text-base text-white hover:bg-black/30 pressed:bg-black/40 transition-colors cursor-default outline-hidden focus-visible:ring-2 focus-visible:ring-white/75">
Press here or type <kbd class="px-2 py-1 text-xs font-semibold border border-gray-200 rounded-lg m-2">Ctrl</kbd> + <kbd class="px-2 py-1 text-xs font-semibold border border-gray-200 rounded-lg m-2">K</kbd> to open command palette
Copy link
Member

Choose a reason for hiding this comment

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

on Mac it appears it's actually Cmd + k

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.

5 participants