-
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: Pass through options
props
#64211
Conversation
@@ -26,6 +26,22 @@ function useUniqueId( idProp?: string ) { | |||
return idProp || id; | |||
} | |||
|
|||
function SelectOptions( { |
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.
Extracted this out from the main component function because we need to pick props from the options.map
and the names are going to conflict with the main component props.
options: NonNullable< SelectControlProps[ 'options' ] >; | ||
} ) { | ||
return options.map( ( { id, label, value, ...optionProps }, index ) => { | ||
const key = id || `${ label }-${ value }-${ index }`; |
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.
As a key
, ${ label }-${ value }-${ index }
seems functionally equivalent to index
🤔 Doesn't seem particularly intentional, either (#6122). I'm not touching this in this PR though.
it( 'should render its children', async () => { | ||
const user = userEvent.setup(); |
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.
Cleaned up some typos.
id?: string; | ||
/** | ||
* Whether or not the option should have the disabled attribute. | ||
* | ||
* @default false | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* Whether or not the option should be hidden. | ||
* | ||
* @default false | ||
*/ | ||
hidden?: boolean; |
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.
Removing these explicit types since they are included in React.OptionHTMLAttributes
.
onBlur?: ( event: FocusEvent< HTMLSelectElement > ) => void; | ||
onFocus?: ( event: FocusEvent< HTMLSelectElement > ) => void; |
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.
Removing these explicit event listener props since they are mixed in here:
gutenberg/packages/components/src/select-control/index.tsx
Lines 45 to 47 in 2c01c7d
function UnforwardedSelectControl( | |
props: WordPressComponentProps< SelectControlProps, 'select', false >, | |
ref: React.ForwardedRef< HTMLSelectElement > |
This will remove them from the props table and auto-generated code snippets in Storybook, which is good because we have no reason to explicitly show onBlur
and onFocus
.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
LGTM 👍
Love the extra SelectControlBaseProps.options
prop type cleanup 👏
The only thing I'd do would be to change the value
description to be a bit more specific for multiple/single.
/** | ||
* The value of the selected option. | ||
* | ||
* If `multiple` is true, the `value` should be an array with the values of the selected options. | ||
*/ |
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.
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.
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.
That's not a great reason for the type description verbosity TBH 😞 I wish Storybook could handle that in a more clever way. Are we the first to have that problem? Seems like this is similar to what we need: storybookjs/storybook#21281
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.
I don't necessarily dislike this limitation though. I think it is useful to know that a prop is conditionally polymorphic.
/** | ||
* The value of the selected option. | ||
* | ||
* If `multiple` is true, the `value` should be an array with the values of the selected options. | ||
*/ |
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.
As above: Does it make sense to make this more multiple-specific, so it's clear that it's always an array of values and not a single value since it's only when the select field is a multiple select one?
Prerequisite for #63815
What?
In
SelectControl
, pass through any extra props defined inoptions
to the underlying<option>
element.Why?
To support any additional
option
attributes, for examplearia-label
.Testing Instructions
In Storybook, pass some additional
option
attributes and see what gets rendered in HTML.✅ Unit test passes