[MM-61619]: Added aria-live property for message sent status (#29720)
* [MA-22]: Added aria-live property for message sent status * Review Fixes: Updated the logic to programmatically change status element's content. * [MA-22]: Rebased with master
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
03b678e860
Коммит
4225b9bac1
@@ -20,6 +20,7 @@ import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'
|
||||
import {getCurrentUserId, isCurrentUserGuestUser, getStatusForUserId, makeGetDisplayName} from 'mattermost-redux/selectors/entities/users';
|
||||
|
||||
import * as GlobalActions from 'actions/global_actions';
|
||||
import type {CreatePostOptions} from 'actions/post_actions';
|
||||
import {actionOnGlobalItemsWithPrefix} from 'actions/storage';
|
||||
import type {SubmitPostReturnType} from 'actions/views/create_comment';
|
||||
import {removeDraft, updateDraft} from 'actions/views/drafts';
|
||||
@@ -197,6 +198,7 @@ const AdvancedTextEditor = ({
|
||||
const draftRef = useRef(draftFromStore);
|
||||
const storedDrafts = useRef<Record<string, PostDraft | undefined>>({});
|
||||
const lastBlurAt = useRef(0);
|
||||
const messageStatusRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const [draft, setDraft] = useState(draftFromStore);
|
||||
const [caretPosition, setCaretPosition] = useState(draft.message.length);
|
||||
@@ -338,6 +340,19 @@ const AdvancedTextEditor = ({
|
||||
isInEditMode,
|
||||
);
|
||||
|
||||
const handleSubmitWithErrorHandling = useCallback((submittingDraft?: PostDraft, schedulingInfo?: SchedulingInfo, options?: CreatePostOptions) => {
|
||||
handleSubmit(submittingDraft, schedulingInfo, options);
|
||||
if (!errorClass) {
|
||||
const messageStatusElement = messageStatusRef.current;
|
||||
const messageStatusInnerText = messageStatusElement?.textContent;
|
||||
if (messageStatusInnerText === 'Message Sent') {
|
||||
messageStatusElement!.textContent = 'Message Sent ';
|
||||
} else {
|
||||
messageStatusElement!.textContent = 'Message Sent';
|
||||
}
|
||||
}
|
||||
}, [errorClass, handleSubmit]);
|
||||
|
||||
const handleCancel = useCallback(() => {
|
||||
handleDraftChange({
|
||||
message: '',
|
||||
@@ -392,8 +407,8 @@ const AdvancedTextEditor = ({
|
||||
handleFileChangesOnSave(draft);
|
||||
}
|
||||
|
||||
handleSubmit();
|
||||
}, [dispatch, draft, handleFileChangesOnSave, handleSubmit, isInEditMode, isRHS]);
|
||||
handleSubmitWithErrorHandling();
|
||||
}, [dispatch, draft, handleFileChangesOnSave, handleSubmitWithErrorHandling, isInEditMode, isRHS]);
|
||||
|
||||
const [handleKeyDown, postMsgKeyPress] = useKeyHandler(
|
||||
draft,
|
||||
@@ -418,8 +433,8 @@ const AdvancedTextEditor = ({
|
||||
|
||||
const handleSubmitWithEvent = useCallback((e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
handleSubmit();
|
||||
}, [handleSubmit]);
|
||||
handleSubmitWithErrorHandling();
|
||||
}, [handleSubmitWithErrorHandling]);
|
||||
|
||||
const handlePostError = useCallback((err: React.ReactNode) => {
|
||||
setPostError(err);
|
||||
@@ -573,7 +588,9 @@ const AdvancedTextEditor = ({
|
||||
draftRef.current = draft;
|
||||
}, [draft]);
|
||||
|
||||
const handleSubmitPostAndScheduledMessage = useCallback((schedulingInfo?: SchedulingInfo) => handleSubmit(undefined, schedulingInfo), [handleSubmit]);
|
||||
const handleSubmitPostAndScheduledMessage = useCallback((schedulingInfo?: SchedulingInfo) => {
|
||||
handleSubmitWithErrorHandling(undefined, schedulingInfo);
|
||||
}, [handleSubmitWithErrorHandling]);
|
||||
|
||||
// Set the draft from store when changing post or channels, and store the previous one
|
||||
useEffect(() => {
|
||||
@@ -865,6 +882,11 @@ const AdvancedTextEditor = ({
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
ref={messageStatusRef}
|
||||
aria-live='assertive'
|
||||
className='sr-only'
|
||||
/>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user