-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
SelectControl: Finish typescript migration #40737
Conversation
Size Change: +2 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
@@ -114,7 +114,7 @@ Render a user interface to select multiple users from a list. | |||
this.setState( { users } ); | |||
} } | |||
options={ [ | |||
{ value: null, label: 'Select a User', disabled: true }, |
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.
null
is not a valid value. Caught by TS in Storybook
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.
So good! That's exactly what TypeScript is great at.
extends Pick< | ||
InputBaseProps, | ||
| 'disabled' | ||
| 'hideLabelFromVision' | ||
| 'label' | ||
| 'labelPosition' | ||
| 'prefix' | ||
| 'size' | ||
| 'suffix' | ||
>, |
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.
This extend of InputBaseProps
used to be a denylist, which brought in way too many irrelevant props here. Now changed to an allowlist.
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.
Great job! 🚀
We can merge this PR as soon as the couple of pending comments are resolved..
@@ -114,7 +114,7 @@ Render a user interface to select multiple users from a list. | |||
this.setState( { users } ); | |||
} } | |||
options={ [ | |||
{ value: null, label: 'Select a User', disabled: true }, |
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.
So good! That's exactly what TypeScript is great at.
/** | ||
* `SelectControl` allows users to select from a single or multiple option menu. | ||
* It functions as a wrapper around the browser's native `<select>` element. | ||
* | ||
* @example | ||
* import { SelectControl } from '@wordpress/components'; | ||
* import { useState } from '@wordpress/element'; | ||
* | ||
* const MySelectControl = () => { | ||
* const [ size, setSize ] = useState( '50%' ); | ||
* | ||
* return ( | ||
* <SelectControl | ||
* label="Size" | ||
* value={ size } | ||
* options={ [ | ||
* { label: 'Big', value: '100%' }, | ||
* { label: 'Medium', value: '50%' }, | ||
* { label: 'Small', value: '25%' }, | ||
* ] } | ||
* onChange={ setSize } | ||
* /> | ||
* ); | ||
* }; | ||
*/ | ||
export const SelectControl = forwardRef( UnforwardedSelectControl ); |
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.
Thank you for adding the JSDoc example 🎉
packages/components/src/select-control/styles/select-control-styles.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Add a named export to `SelectControl` so the native module aligns with the web module. The use of a named export was added to code shared between web and native. Because the latter only defined a default export, an error was thrown. - Named export added: #40737 - Named export used: #41536 I am uncertain as to why a named export was added originally. My presumption is that it was recently used so that the import was a local reference, instead of a importing the module's top-level entry file.
Add a named export to `SelectControl` so the native module aligns with the web module. The use of a named export was added to code shared between web and native. Because the latter only defined a default export, an error was thrown. - Named export added: #40737 - Named export used: #41536 I am uncertain as to why a named export was added originally. My presumption is that it was recently used so that the import was a local reference, instead of a importing the module's top-level entry file.
Add a named export to `SelectControl` so the native module aligns with the web module. The use of a named export was added to code shared between web and native. Because the latter only defined a default export, an error was thrown. - Named export added: #40737 - Named export used: #41536 I am uncertain as to why a named export was added originally. My presumption is that it was recently used so that the import was a local reference, instead of a importing the module's top-level entry file.
In preparation for #39397
Part of #35744
Part of #35665
What?
Although the
SelectControl
component was already in typescript, this PR fixes some type mistakes and finishes up the TS migration process.InputBase
but were not applicable to SelectControl.Why?
As part of the ongoing effort to improve code quality and devex.
Testing Instructions
npm run storybook:dev
SelectControl
.