[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 {getCurrentUserId, isCurrentUserGuestUser, getStatusForUserId, makeGetDisplayName} from 'mattermost-redux/selectors/entities/users';
|
||||||
|
|
||||||
import * as GlobalActions from 'actions/global_actions';
|
import * as GlobalActions from 'actions/global_actions';
|
||||||
|
import type {CreatePostOptions} from 'actions/post_actions';
|
||||||
import {actionOnGlobalItemsWithPrefix} from 'actions/storage';
|
import {actionOnGlobalItemsWithPrefix} from 'actions/storage';
|
||||||
import type {SubmitPostReturnType} from 'actions/views/create_comment';
|
import type {SubmitPostReturnType} from 'actions/views/create_comment';
|
||||||
import {removeDraft, updateDraft} from 'actions/views/drafts';
|
import {removeDraft, updateDraft} from 'actions/views/drafts';
|
||||||
@@ -197,6 +198,7 @@ const AdvancedTextEditor = ({
|
|||||||
const draftRef = useRef(draftFromStore);
|
const draftRef = useRef(draftFromStore);
|
||||||
const storedDrafts = useRef<Record<string, PostDraft | undefined>>({});
|
const storedDrafts = useRef<Record<string, PostDraft | undefined>>({});
|
||||||
const lastBlurAt = useRef(0);
|
const lastBlurAt = useRef(0);
|
||||||
|
const messageStatusRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const [draft, setDraft] = useState(draftFromStore);
|
const [draft, setDraft] = useState(draftFromStore);
|
||||||
const [caretPosition, setCaretPosition] = useState(draft.message.length);
|
const [caretPosition, setCaretPosition] = useState(draft.message.length);
|
||||||
@@ -338,6 +340,19 @@ const AdvancedTextEditor = ({
|
|||||||
isInEditMode,
|
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(() => {
|
const handleCancel = useCallback(() => {
|
||||||
handleDraftChange({
|
handleDraftChange({
|
||||||
message: '',
|
message: '',
|
||||||
@@ -392,8 +407,8 @@ const AdvancedTextEditor = ({
|
|||||||
handleFileChangesOnSave(draft);
|
handleFileChangesOnSave(draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit();
|
handleSubmitWithErrorHandling();
|
||||||
}, [dispatch, draft, handleFileChangesOnSave, handleSubmit, isInEditMode, isRHS]);
|
}, [dispatch, draft, handleFileChangesOnSave, handleSubmitWithErrorHandling, isInEditMode, isRHS]);
|
||||||
|
|
||||||
const [handleKeyDown, postMsgKeyPress] = useKeyHandler(
|
const [handleKeyDown, postMsgKeyPress] = useKeyHandler(
|
||||||
draft,
|
draft,
|
||||||
@@ -418,8 +433,8 @@ const AdvancedTextEditor = ({
|
|||||||
|
|
||||||
const handleSubmitWithEvent = useCallback((e: React.FormEvent) => {
|
const handleSubmitWithEvent = useCallback((e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleSubmit();
|
handleSubmitWithErrorHandling();
|
||||||
}, [handleSubmit]);
|
}, [handleSubmitWithErrorHandling]);
|
||||||
|
|
||||||
const handlePostError = useCallback((err: React.ReactNode) => {
|
const handlePostError = useCallback((err: React.ReactNode) => {
|
||||||
setPostError(err);
|
setPostError(err);
|
||||||
@@ -573,7 +588,9 @@ const AdvancedTextEditor = ({
|
|||||||
draftRef.current = draft;
|
draftRef.current = draft;
|
||||||
}, [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
|
// Set the draft from store when changing post or channels, and store the previous one
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -865,6 +882,11 @@ const AdvancedTextEditor = ({
|
|||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<div
|
||||||
|
ref={messageStatusRef}
|
||||||
|
aria-live='assertive'
|
||||||
|
className='sr-only'
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user