-
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
CustomSelectControl: Restore describedBy
functionality
#63957
Conversation
<VisuallyHidden> | ||
<span id={ descriptionId }> | ||
{ getDescribedBy( currentValue, describedBy ) } | ||
</span> | ||
</VisuallyHidden> |
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 original implementation passed the describedBy
prop down to Button
. Therefore, we want to replicate how Button rendered the describedBy
text.
gutenberg/packages/components/src/button/index.tsx
Lines 282 to 284 in cad81e4
<VisuallyHidden> | |
<span id={ descriptionId }>{ description }</span> | |
</VisuallyHidden> |
function getDescribedBy( currentValue: string, describedBy?: string ) { | ||
if ( describedBy ) { | ||
return describedBy; | ||
} | ||
|
||
// translators: %s: The selected option. | ||
return sprintf( __( 'Currently selected: %s' ), currentValue ); | ||
} |
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 function copies the original logic, which looked like this:
gutenberg/packages/components/src/custom-select-control/index.js
Lines 130 to 141 in 9bb75b3
function getDescribedBy() { | |
if ( describedBy ) { | |
return describedBy; | |
} | |
if ( ! selectedItem ) { | |
return __( 'No selection' ); | |
} | |
// translators: %s: The selected option. | |
return sprintf( __( 'Currently selected: %s' ), selectedItem.name ); | |
} |
I removed the case for no selection, because that won't happen in this Ariakit-based version.
// Forward props + store from v2 implementation | ||
const store = Ariakit.useSelectStore( { | ||
const store = Ariakit.useSelectStore< 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.
The Ariakit store allows string | string[]
because it can handle multiple selection. Since this v1 never supported multiple selection, let's narrow the type to just string
. (This has the effect of narrowing the type of store.getState().value
to string.)
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.
Please remember to manually add props to @rohitmathur-7 for the alternative PR at #63884 |
Fixes #63568
What?
Restores the
describedBy
functionality in CustomSelectControl (v1) that was broken when we switched the underlying implementation in #63258.How?
See code comments.
Testing Instructions
New unit tests should pass. You can also manually inspect the rendered HTML in Storybook.