-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(autocomplete): add autoHighlight prop #3829
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6bc348e
feat(autocomplete): add isAutoHighlight prop to automatically highlig…
dgz9 6a260a3
Merge branch 'nextui-org:canary' into feat/autocomplete-highlight
dgz9 094efcb
feat(autocomplete): add isAutoHighlight prop
dgz9 2a313e8
docs: replace isAutoHighlight with autoHighlight
dgz9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@nextui-org/autocomplete": minor | ||
| "@nextui-org/listbox": minor | ||
| --- | ||
|
|
||
| add prop autoHighlight to enable/disable the automatic focus on autocomplete items (#2186) |
53 changes: 53 additions & 0 deletions
53
apps/docs/content/components/autocomplete/auto-highlight.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const data = `export const animals = [ | ||
| {label: "Cat", value: "cat", description: "The second most popular pet in the world"}, | ||
| {label: "Dog", value: "dog", description: "The most popular pet in the world"}, | ||
| {label: "Elephant", value: "elephant", description: "The largest land animal"}, | ||
| {label: "Lion", value: "lion", description: "The king of the jungle"}, | ||
| {label: "Tiger", value: "tiger", description: "The largest cat species"}, | ||
| {label: "Giraffe", value: "giraffe", description: "The tallest land animal"}, | ||
| { | ||
| label: "Dolphin", | ||
| value: "dolphin", | ||
| description: "A widely distributed and diverse group of aquatic mammals", | ||
| }, | ||
| {label: "Penguin", value: "penguin", description: "A group of aquatic flightless birds"}, | ||
| {label: "Zebra", value: "zebra", description: "A several species of African equids"}, | ||
| { | ||
| label: "Shark", | ||
| value: "shark", | ||
| description: "A group of elasmobranch fish characterized by a cartilaginous skeleton", | ||
| }, | ||
| { | ||
| label: "Whale", | ||
| value: "whale", | ||
| description: "Diverse group of fully aquatic placental marine mammals", | ||
| }, | ||
| {label: "Otter", value: "otter", description: "A carnivorous mammal in the subfamily Lutrinae"}, | ||
| {label: "Crocodile", value: "crocodile", description: "A large semiaquatic reptile"}, | ||
| ];`; | ||
|
|
||
| const App = `import {Autocomplete, AutocompleteItem} from "@nextui-org/react"; | ||
| import {animals} from "./data"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <Autocomplete | ||
| autoHighlight | ||
| label="Favorite Animal" | ||
| placeholder="Search an animal" | ||
| className="max-w-xs" | ||
| defaultItems={animals} | ||
| > | ||
| {(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>} | ||
| </Autocomplete> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| "/data.js": data, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,11 @@ export default { | |
| type: "boolean", | ||
| }, | ||
| }, | ||
| autoHighlight: { | ||
| control: { | ||
| type: "boolean", | ||
| }, | ||
| }, | ||
| validationBehavior: { | ||
| control: { | ||
| type: "select", | ||
|
|
@@ -803,6 +808,21 @@ const WithReactHookFormTemplate = (args: AutocompleteProps) => { | |
| ); | ||
| }; | ||
|
|
||
| const AutoHighlightTemplate = ({color, variant, ...args}: AutocompleteProps<Animal>) => ( | ||
| <Autocomplete | ||
| autoHighlight | ||
| className="max-w-xs" | ||
| color={color} | ||
| defaultItems={animalsData} | ||
| label="Favorite Animal" | ||
| placeholder="Select an animal" | ||
| variant={variant} | ||
| {...args} | ||
| > | ||
| {(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>} | ||
| </Autocomplete> | ||
| ); | ||
|
|
||
| export const Default = { | ||
| render: Template, | ||
| args: { | ||
|
|
@@ -1061,3 +1081,10 @@ export const FullyControlled = { | |
| ...defaultProps, | ||
| }, | ||
| }; | ||
|
|
||
| export const WithAutoHighlight = { | ||
| render: AutoHighlightTemplate, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no need to create a new template for that. You can simply use |
||
| args: { | ||
| ...defaultProps, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,11 @@ interface Props<T> extends Omit<HTMLNextUIProps<"ul">, "children"> { | |
| * The menu items classNames. | ||
| */ | ||
| itemClasses?: ListboxItemProps["classNames"]; | ||
| /** | ||
| * Whether to automatically highlight the first item in the list. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first non-disabled item |
||
| * @default false | ||
| */ | ||
| autoHighlight?: boolean; | ||
| } | ||
|
|
||
| export type UseListboxProps<T = object> = Props<T> & AriaListBoxOptions<T> & ListboxVariantProps; | ||
|
|
@@ -118,6 +123,7 @@ export function useListbox<T extends object>(props: UseListboxProps<T>) { | |
| hideEmptyContent = false, | ||
| shouldHighlightOnFocus = false, | ||
| classNames, | ||
| autoHighlight = false, | ||
| ...otherProps | ||
| } = props; | ||
|
|
||
|
|
@@ -181,6 +187,7 @@ export function useListbox<T extends object>(props: UseListboxProps<T>) { | |
| disableAnimation, | ||
| className, | ||
| itemClasses, | ||
| autoHighlight, | ||
| getBaseProps, | ||
| getListProps, | ||
| getEmptyContentProps, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.