Fix ugly Combobox loading state (#38778)

This commit is contained in:
diondiondion 2026-04-22 15:33:34 +02:00 committed by GitHub
parent 1cae543e8f
commit e3c0883d32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 4 deletions

View File

@ -76,6 +76,26 @@
} }
.emptyMessage { .emptyMessage {
padding: 8px 16px; display: flex;
flex-direction: column;
align-items: center;
text-align: center;
gap: 8px;
padding: 16px;
font-size: 13px; font-size: 13px;
} }
.loadingIndicator {
--spinner-size: 20px;
position: relative;
display: block;
width: var(--spinner-size);
height: var(--spinner-size);
overflow: hidden;
& :global(.circular-progress) {
width: var(--spinner-size);
height: var(--spinner-size);
}
}

View File

@ -22,6 +22,8 @@ import { matchWidth } from 'mastodon/components/dropdown/utils';
import { IconButton } from 'mastodon/components/icon_button'; import { IconButton } from 'mastodon/components/icon_button';
import { useOnClickOutside } from 'mastodon/hooks/useOnClickOutside'; import { useOnClickOutside } from 'mastodon/hooks/useOnClickOutside';
import { LoadingIndicator } from '../loading_indicator';
import classes from './combobox.module.scss'; import classes from './combobox.module.scss';
import { FormFieldWrapper } from './form_field_wrapper'; import { FormFieldWrapper } from './form_field_wrapper';
import type { CommonFieldWrapperProps } from './form_field_wrapper'; import type { CommonFieldWrapperProps } from './form_field_wrapper';
@ -531,6 +533,7 @@ const ComboboxWithRef = <Item extends ComboboxItem, GroupKey extends string>(
<div {...props} className={classNames(classes.popover, placement)}> <div {...props} className={classNames(classes.popover, placement)}>
<StatusMessageWrapper <StatusMessageWrapper
showStatus={showStatusMessageInMenu} showStatus={showStatusMessageInMenu}
isLoading={isLoading}
status={statusMessage} status={statusMessage}
> >
{hasGroups ? ( {hasGroups ? (
@ -592,10 +595,20 @@ Combobox.displayName = 'Combobox';
const StatusMessageWrapper: React.FC<{ const StatusMessageWrapper: React.FC<{
showStatus: boolean; showStatus: boolean;
status: string; status: string;
isLoading: boolean;
children: React.ReactNode; children: React.ReactNode;
}> = ({ showStatus, status, children }) => { }> = ({ showStatus, status, isLoading, children }) => {
if (showStatus) { if (showStatus) {
return <span className={classes.emptyMessage}>{status}</span>; return (
<span className={classes.emptyMessage}>
{isLoading && (
<span className={classes.loadingIndicator}>
<LoadingIndicator role='none' />
</span>
)}
{status}
</span>
);
} }
return children; return children;

View File

@ -331,6 +331,10 @@ const TopicField: React.FC = () => {
[topic], [topic],
); );
const isCurrentTopicOnlySuggestion =
tags.length === 1 && tags[0]?.id === 'new';
const hideTagSuggestions = !tags.length || isCurrentTopicOnlySuggestion;
return ( return (
<ComboboxField <ComboboxField
required={false} required={false}
@ -369,7 +373,7 @@ const TopicField: React.FC = () => {
} }
: undefined : undefined
} }
suppressMenu={!tags.length} suppressMenu={hideTagSuggestions}
/> />
); );
}; };