-
Notifications
You must be signed in to change notification settings - Fork 4.6k
CustomSelectControl: support generic props type #63985
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 1 commit
4f5c724
478581c
7c28ddf
162aa1d
1aaf455
19c5f92
987a017
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import _CustomSelect from '../custom-select-control-v2/custom-select'; | |
| import CustomSelectItem from '../custom-select-control-v2/item'; | ||
| import * as Styled from '../custom-select-control-v2/styles'; | ||
| import type { CustomSelectProps, CustomSelectOption } from './types'; | ||
| import { VisuallyHidden } from '../visually-hidden'; | ||
|
|
||
| function useDeprecatedProps< T extends CustomSelectOption >( { | ||
| __experimentalShowSelectedHint, | ||
|
|
@@ -41,6 +42,15 @@ function applyOptionDeprecations( { | |
| }; | ||
| } | ||
|
|
||
| function getDescribedBy( currentValue: string, describedBy?: string ) { | ||
| if ( describedBy ) { | ||
| return describedBy; | ||
| } | ||
|
|
||
| // translators: %s: The selected option. | ||
| return sprintf( __( 'Currently selected: %s' ), currentValue ); | ||
| } | ||
|
|
||
| function CustomSelectControl< T extends CustomSelectOption >( | ||
|
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. Should we add a default to the generic so any existing consumers will continue working without changing anything? The same question applies to all instances where we're adding a generic and there wasn't one before.
Contributor
Author
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. The generic param is not going to be set manually by user. It's used for type inferring. To be specific, it will use the item type of the You could checkout this branch and test with the snippets that pasted in the "Testing Instructions" section.
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. TypeScript should always be able to infer the |
||
| props: CustomSelectProps< T > | ||
| ) { | ||
|
|
||
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.
Since this is a type change, I believe it should be under
Internalinstead.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.
Cuz the type will be used by user, and will improve the developer experience, I think it's more of an improvement / enhancement?
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.
IMHO, types and type changes are an internal kind of enhancement, and we have this "Internal" group to distinguish them. General Enhancements would usually be targeted towards end users.