-
Notifications
You must be signed in to change notification settings - Fork 70
fix: update autocomplete types to require optionLabel when using objects and optional for strings/numbers #4279
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,8 +124,8 @@ type IndexFinderType = <T,>({ | |||||||||||||||||||||||||||||||||||||||
| allDisabled, | ||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||
| index: number | ||||||||||||||||||||||||||||||||||||||||
| optionDisabled: AutocompleteProps<T>['optionDisabled'] | ||||||||||||||||||||||||||||||||||||||||
| availableItems: AutocompleteProps<T>['options'] | ||||||||||||||||||||||||||||||||||||||||
| optionDisabled: (option: T) => boolean | ||||||||||||||||||||||||||||||||||||||||
| availableItems: readonly T[] | ||||||||||||||||||||||||||||||||||||||||
| allDisabled?: boolean | ||||||||||||||||||||||||||||||||||||||||
| calc?: (n: number) => number | ||||||||||||||||||||||||||||||||||||||||
| }) => number | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -235,7 +235,7 @@ const defaultOptionDisabled = () => false | |||||||||||||||||||||||||||||||||||||||
| // MARK: types | ||||||||||||||||||||||||||||||||||||||||
| export type AutocompleteChanges<T> = { selectedItems: T[] } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export type AutocompleteProps<T> = { | ||||||||||||||||||||||||||||||||||||||||
| export type AutocompleteProps<T = string> = { | ||||||||||||||||||||||||||||||||||||||||
| /** List of options in dropdown */ | ||||||||||||||||||||||||||||||||||||||||
| options: readonly T[] | ||||||||||||||||||||||||||||||||||||||||
| /** Total number of options */ | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -293,8 +293,6 @@ export type AutocompleteProps<T> = { | |||||||||||||||||||||||||||||||||||||||
| multiple?: boolean | ||||||||||||||||||||||||||||||||||||||||
| /** Add select-all option. Throws an error if true while multiple = false */ | ||||||||||||||||||||||||||||||||||||||||
| allowSelectAll?: boolean | ||||||||||||||||||||||||||||||||||||||||
| /** Custom option label. NOTE: This is required when option is an object */ | ||||||||||||||||||||||||||||||||||||||||
| optionLabel?: (option: T) => string | ||||||||||||||||||||||||||||||||||||||||
| /** Custom option template */ | ||||||||||||||||||||||||||||||||||||||||
| optionComponent?: (option: T, isSelected: boolean) => ReactNode | ||||||||||||||||||||||||||||||||||||||||
| /** Disable option | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -333,7 +331,21 @@ export type AutocompleteProps<T> = { | |||||||||||||||||||||||||||||||||||||||
| * Callback for clear all button | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| onClear?: () => void | ||||||||||||||||||||||||||||||||||||||||
| } & HTMLAttributes<HTMLDivElement> | ||||||||||||||||||||||||||||||||||||||||
| } & HTMLAttributes<HTMLDivElement> & | ||||||||||||||||||||||||||||||||||||||||
| (T extends string | number | ||||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||||
| /** Custom option label. NOTE: This is required when option is an object */ | ||||||||||||||||||||||||||||||||||||||||
| optionLabel?: (option: T) => string | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| : T extends object | ||||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||||
| /** Custom option label. NOTE: This is required when option is an object */ | ||||||||||||||||||||||||||||||||||||||||
| optionLabel: (option: T) => string | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| : { | ||||||||||||||||||||||||||||||||||||||||
| /** Custom option label. NOTE: This is required when option is an object */ | ||||||||||||||||||||||||||||||||||||||||
| optionLabel?: (option: T) => string | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+337
to
+348
|
||||||||||||||||||||||||||||||||||||||||
| /** Custom option label. NOTE: This is required when option is an object */ | |
| optionLabel?: (option: T) => string | |
| } | |
| : T extends object | |
| ? { | |
| /** Custom option label. NOTE: This is required when option is an object */ | |
| optionLabel: (option: T) => string | |
| } | |
| : { | |
| /** Custom option label. NOTE: This is required when option is an object */ | |
| optionLabel?: (option: T) => string | |
| }) | |
| /** Custom option label. NOTE: This is optional for primitive types */ | |
| optionLabel?: (option: T) => string | |
| } | |
| : { | |
| /** Custom option label. NOTE: This is required when option is an object */ | |
| optionLabel: (option: T) => string | |
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might look like its not need but removing breaks the types when somebody tries to wrap it using the styled from styled components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comments for
optionLabelin all three branches are identical: "Custom option label. NOTE: This is required when option is an object". This is misleading because in the first branch (lines 336-339),optionLabelis actually optional forstring | numbertypes.The comment on line 337 should be updated to reflect that it's optional for primitive types: