Skip to content

Commit

Permalink
[MM-61619]: Added aria-live property for message sent status (matterm…
Browse files Browse the repository at this point in the history
…ost#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
  • Loading branch information
ayush-chauhan233 authored Jan 21, 2025
1 parent 03b678e commit 4225b9b
Showing 1 changed file with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 &nbsp;';
} else {
messageStatusElement!.textContent = 'Message Sent';
}
}
}, [errorClass, handleSubmit]);

const handleCancel = useCallback(() => {
handleDraftChange({
message: '',
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -865,6 +882,11 @@ const AdvancedTextEditor = ({
onCancel={handleCancel}
/>
)}
<div
ref={messageStatusRef}
aria-live='assertive'
className='sr-only'
/>
</form>
);
};
Expand Down

0 comments on commit 4225b9b

Please sign in to comment.