-
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
Changes from 8 commits
f73720d
76488c1
3c7baa6
07690d6
736c5ff
fd97afc
3a357c4
374b2b8
45bbc6b
cc0e64a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ function MyComboboxControl() { | |
label="Font Size" | ||
value={ fontSize } | ||
onChange={ setFontSize } | ||
isLoading={ isLoading } | ||
options={ filteredOptions } | ||
onFilterValueChange={ ( inputValue ) => | ||
setFilteredOptions( | ||
|
@@ -112,13 +113,20 @@ If the control is clicked, the dropdown will expand regardless of this prop. | |
- Required: No | ||
- Default: `true` | ||
|
||
### placeholder | ||
#### placeholder | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's match the same description as the one from 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. matched |
||
|
||
- Type: `Boolean` | ||
- Required: No | ||
|
||
#### __experimentalRenderItem | ||
|
||
Custom renderer invoked for each option in the suggestion list. The render prop receives as its argument an object containing, under the `item` key, the single option's data (directly from the array of data passed to the `options` prop). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import type { TokenInputProps } from '../form-token-field/types'; | |
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props'; | ||
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events'; | ||
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size'; | ||
import Spinner from '../spinner'; | ||
|
||
const noop = () => {}; | ||
|
||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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. |
||
messages = { | ||
selected: __( 'Item selected.' ), | ||
}, | ||
|
@@ -362,6 +364,7 @@ function ComboboxControl( props: ComboboxControlProps ) { | |
onChange={ onInputChange } | ||
/> | ||
</FlexBlock> | ||
{ isLoading && <Spinner /> } | ||
{ allowReset && ( | ||
<Button | ||
size="small" | ||
|
@@ -375,7 +378,7 @@ function ComboboxControl( props: ComboboxControlProps ) { | |
/> | ||
) } | ||
</InputWrapperFlex> | ||
{ isExpanded && ( | ||
{ isExpanded && ! isLoading && ( | ||
<SuggestionsList | ||
instanceId={ instanceId } | ||
// The empty string for `value` here is not actually used, but is | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ export default function PostAuthorCombobox() { | |
const [ fieldValue, setFieldValue ] = useState(); | ||
|
||
const { editPost } = useDispatch( editorStore ); | ||
const { authorId, authorOptions } = useAuthorsQuery( fieldValue ); | ||
const { authorId, authorOptions, isLoading } = | ||
useAuthorsQuery( fieldValue ); | ||
|
||
/** | ||
* Handle author selection. | ||
|
@@ -51,6 +52,7 @@ export default function PostAuthorCombobox() { | |
onChange={ handleSelect } | ||
allowReset={ false } | ||
hideLabelFromVision | ||
isLoading={ isLoading } | ||
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. My preference would we to focus this PR solely on the 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 commentThe 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 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 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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.
🙏