-
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
Add loading indicator to combo box control author selector #68927
Add loading indicator to combo box control author selector #68927
Conversation
Note: the drop-down shows "No items found." during the search, a bug clearly visible currently (before this PR) when throttling the search callback. |
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. |
I updated the PR to avoid showing "No items found" string while the results are still loading. |
@@ -44,13 +45,14 @@ export default function PostAuthorCombobox() { | |||
<ComboboxControl | |||
__nextHasNoMarginBottom | |||
__next40pxDefaultSize | |||
label={ __( 'Author' ) } | |||
label={ __( 'Authorz' ) } |
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.
Typo?
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.
ha, this was me trying to get my build working and not seeing changes. will revert!
@@ -157,7 +158,7 @@ export function SuggestionsList< | |||
); | |||
/* eslint-enable jsx-a11y/click-events-have-key-events */ | |||
} ) } | |||
{ suggestions.length === 0 && ( | |||
{ suggestions.length === 0 && ! isLoading && ( |
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 SuggestionsList
component is shared, which is why we're passing the isLoading
prop, correct?
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.
right
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.
Thanks, @adamsilverstein!
My suggestion is to limit new loading state changes to the ComboboxControl
. The FormTokenField
component is a bit tricky, as input and tokens can wrap on multiple lines. So, I'm not sure if the spinner suffix design will work for it.
Do you mind including a screenshot or screencast in the PR description?
Hopefully, the v2 design will account for the loading state of #64086.
cc @WordPress/gutenberg-components
Thanks for the review. I will add some screenshots/screencasts to show what this change does (when I am back at my desk Friday). I can also take a look at other consumers of the component to make sure they are unaffected. The main goal of the change here is to avoid showing "No items found" string while the (author) search is underway. Since it isn't directly related to adding a spinner, I can break it out into a follow up PR and we can explore the issue separately. |
I think it's okay to change the |
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.
Finally, I would also suggest
options={ authorOptions } | ||
value={ authorId } | ||
onFilterValueChange={ debounce( handleKeydown, 300 ) } | ||
onChange={ handleSelect } | ||
allowReset={ false } | ||
hideLabelFromVision | ||
isLoading={ isLoading } |
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.
My preference would we to focus this PR solely on the ComboboxControl
component.
We should add a Storybook example here to allow for easy testing of the component in isolation.
In a separate, follow-up PR, we could then tweak the post author combobox to use the new prop
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 entire point of this PR is to improve the author selector - changing only the combobox won't actually change anything, shouldn't we aim for PRs that actually improve things?
I can look into adding to the storybook, would this just be a variation with the isLoading
prop?
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 @wordpress/component
package is not only used in the Gutenberg repository, but it's also used by third-party developers. Therefore, we usually try to keep changes to the "library" separate from changes to the Gutenberg app (hence why I suggest testing the changes in isolation in Storybook).
Having smaller and more focused PRs is also easier to review, and understand for a future developer stumbling upon it.
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.
Having smaller and more focused PRs is also easier to review, and understand for a future developer stumbling upon it.
I understand the principal, however this entire PR is currently less than 35 lines modified so I think is already easy to review and understand! Given the testing instructions I provided, I feel having the PR do something makes it easier to test and understand.
That said, I sense that you feel strongly about this and I will defer to your more recent experience building here. I will split the combobox and author changes into separate PRs.
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.
@@ -126,6 +127,7 @@ function ComboboxControl( props: ComboboxControlProps ) { | |||
help, | |||
allowReset = true, | |||
className, | |||
isLoading = false, |
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.
Adding this prop won't affect existing usages, although I wonder if it's a good idea, API-wise.
The component doesn't have a canonical example of how to use it with asynchronously loaded options, and I wonder if adding this prop will improve the DevX (related to #55574) — @WordPress/gutenberg-components what do you think?
If we want to encourage this pattern, we should at least add a Storybook example about it?
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 wonder if adding this prop will improve the DevX
Not sure about DevX, this change is about improving User Experience. As is, the combobox selector provides a poor UX when the internet connection is slow or unreliable. The user has no way of knowing that a search is underway during the async search. This shortcoming was overlooked when we originally built the component and I feel this more of a bug than an enhancement.
I will remove these changes for now and we can consider adding them in a follow up PR. I have included screencasts above so you can see why I added this change in the first place. |
Co-authored-by: Marco Ciampini <[email protected]>
This reverts commit 76488c1.
Reverted in fd97afc |
@@ -112,13 +113,20 @@ If the control is clicked, the dropdown will expand regardless of this prop. | |||
- Required: No | |||
- Default: `true` | |||
|
|||
### placeholder | |||
#### placeholder |
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.
🙏
|
||
If passed, the combobox input will show a placeholder string if no values are present. | ||
|
||
- Type: `string` | ||
- Required: No | ||
|
||
#### isLoading | ||
|
||
If true, the dropdown will show a loading indicator. |
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.
Let's match the same description as the one from types.ts
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.
matched
This PR is a rework of the effort in #27865 - see that ticket for additional details.
Testing instructions
Expected results:
Helpful wp-cli commands for testing:
Generate many users to test searching:
wp user generate --role=editor --count=100
Delete test users:
wp user delete $(wp user list --role=editor --field=ID) --reassign=2
Screencasts
Before changes (trunk)
before2.mp4
Add spinner
(note message "No items found" shows during search callback)
spinner-only.mp4
Final PR
(including removal of "No items found" during load)
after.mp4