Skip to content

Commit f771dd3

Browse files
feat: WCAG 3.3.1 inline error in report message modal (#36308)
Co-authored-by: Douglas Fabris <[email protected]>
1 parent ef47698 commit f771dd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+80
-268
lines changed

.changeset/thirty-donuts-visit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/i18n': minor
3+
'@rocket.chat/meteor': minor
4+
---
5+
6+
Improves inline error in report message modal to meet WCAG compliance.

apps/meteor/client/views/room/modals/ReportMessageModal/ReportMessageModal.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { IMessage } from '@rocket.chat/core-typings';
22
import { css } from '@rocket.chat/css-in-js';
3-
import { TextAreaInput, FieldGroup, Field, FieldRow, FieldError, Box } from '@rocket.chat/fuselage';
3+
import { TextAreaInput, FieldGroup, Field, FieldRow, FieldError, FieldLabel, FieldDescription, Box } from '@rocket.chat/fuselage';
44
import { GenericModal } from '@rocket.chat/ui-client';
5-
import { useToastMessageDispatch, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
5+
import { useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts';
66
import type { ReactElement } from 'react';
7-
import { useForm } from 'react-hook-form';
7+
import { useId } from 'react';
8+
import { useForm, Controller } from 'react-hook-form';
9+
import { useTranslation } from 'react-i18next';
810

911
import MarkdownText from '../../../../components/MarkdownText';
1012
import MessageContentBody from '../../../../components/message/MessageContentBody';
@@ -23,12 +25,17 @@ const wordBreak = css`
2325
`;
2426

2527
const ReportMessageModal = ({ message, onClose }: ReportMessageModalProps): ReactElement => {
26-
const t = useTranslation();
28+
const { t } = useTranslation();
29+
const reasonForReportId = useId();
2730
const {
28-
register,
31+
control,
2932
formState: { errors },
3033
handleSubmit,
31-
} = useForm<ReportMessageModalsFields>();
34+
} = useForm<ReportMessageModalsFields>({
35+
defaultValues: {
36+
description: '',
37+
},
38+
});
3239
const dispatchToastMessage = useToastMessageDispatch();
3340
const reportMessage = useEndpoint('POST', '/v1/chat.reportMessage');
3441

@@ -49,20 +56,39 @@ const ReportMessageModal = ({ message, onClose }: ReportMessageModalProps): Reac
4956
<GenericModal
5057
wrapperFunction={(props) => <Box is='form' onSubmit={handleSubmit(handleReportMessage)} {...props} />}
5158
variant='danger'
52-
title={t('Report_this_message_question_mark')}
53-
onClose={onClose}
59+
title={t('Report_message')}
5460
onCancel={onClose}
55-
confirmText={t('Report_exclamation_mark')}
61+
confirmText={t('Report')}
5662
>
5763
<Box mbe={24} className={wordBreak}>
5864
{message.md ? <MessageContentBody md={message.md} /> : <MarkdownText variant='inline' parseEmoji content={message.msg} />}
5965
</Box>
6066
<FieldGroup>
6167
<Field>
68+
<FieldLabel htmlFor={reasonForReportId}>{t('Report_reason')}</FieldLabel>
69+
<FieldDescription id={`${reasonForReportId}-description`}>{t('Let_moderators_know_what_the_issue_is')}</FieldDescription>
6270
<FieldRow>
63-
<TextAreaInput {...register('description', { required: true })} placeholder={t('Why_do_you_want_to_report_question_mark')} />
71+
<Controller
72+
rules={{ required: t('Required_field', { field: t('Report_reason') }) }}
73+
name='description'
74+
control={control}
75+
render={({ field }) => (
76+
<TextAreaInput
77+
{...field}
78+
id={reasonForReportId}
79+
rows={3}
80+
aria-required='true'
81+
aria-invalid={!!errors.description}
82+
aria-describedby={`${reasonForReportId}-description ${reasonForReportId}-error`}
83+
/>
84+
)}
85+
/>
6486
</FieldRow>
65-
{errors.description && <FieldError>{t('You_need_to_write_something')}</FieldError>}
87+
{errors.description && (
88+
<FieldError role='alert' id={`${reasonForReportId}-error`}>
89+
{errors.description.message}
90+
</FieldError>
91+
)}
6692
</Field>
6793
</FieldGroup>
6894
</GenericModal>
Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
import type { Locator, Page } from '@playwright/test';
22

3-
export class ReportMessageModal {
4-
private readonly page: Page;
3+
import { Modal } from './modal';
4+
import { ToastMessages } from './toast-messages';
5+
import { expect } from '../../utils/test';
6+
7+
export class ReportMessageModal extends Modal {
8+
readonly toastMessage: ToastMessages;
59

610
constructor(page: Page) {
7-
this.page = page;
11+
super(page.getByRole('dialog', { name: 'Report message' }));
12+
this.toastMessage = new ToastMessages(page);
813
}
914

1015
get inputReportDescription(): Locator {
11-
return this.page.getByRole('dialog').getByRole('textbox', { name: 'Why do you want to report?' });
16+
return this.root.getByRole('textbox', { name: 'Report reason' });
17+
}
18+
19+
private get btnSubmitReport(): Locator {
20+
return this.root.getByRole('button', { name: 'Report' });
1221
}
1322

14-
get btnSubmitReport(): Locator {
15-
return this.page.getByRole('dialog').getByRole('button', { name: 'Report!' });
23+
private get btnCancelReport(): Locator {
24+
return this.root.getByRole('button', { name: 'Cancel' });
1625
}
1726

18-
get btnCancelReport(): Locator {
19-
return this.page.getByRole('dialog').getByRole('button', { name: 'Cancel' });
27+
private get alertInputDescription(): Locator {
28+
return this.root.getByRole('alert');
2029
}
2130

22-
get reportDescriptionError(): Locator {
23-
return this.page.getByRole('dialog').getByText('You need to write something!');
31+
async cancelReport(): Promise<void> {
32+
await this.btnCancelReport.click();
33+
await this.waitForDismissal();
2434
}
2535

26-
get modalTitle(): Locator {
27-
return this.page.getByRole('dialog').getByText('Report this message?');
36+
async submitReport(description?: string): Promise<void> {
37+
if (!description) {
38+
await this.btnSubmitReport.click();
39+
await expect(this.alertInputDescription).toBeVisible();
40+
return;
41+
}
42+
43+
await this.inputReportDescription.fill(description);
44+
await this.btnSubmitReport.click();
45+
await this.waitForDismissal();
46+
await this.toastMessage.waitForDisplay({ type: 'success', message: 'Report has been sent' });
2847
}
2948
}

apps/meteor/tests/e2e/report-message.spec.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ test.describe.serial('report message', () => {
7979

8080
await adminHomeChannel.content.openLastMessageMenu();
8181
await adminPage.getByRole('menuitem', { name: 'Report' }).click();
82-
83-
await reportModal.btnSubmitReport.click();
84-
await expect(reportModal.reportDescriptionError).toBeVisible();
82+
await reportModal.submitReport();
8583
});
8684
});
8785

@@ -98,10 +96,7 @@ test.describe.serial('report message', () => {
9896

9997
await adminHomeChannel.content.openLastMessageMenu();
10098
await adminPage.getByRole('menuitem', { name: 'Report' }).click();
101-
102-
await expect(reportModal.modalTitle).toBeVisible();
103-
await reportModal.btnCancelReport.click();
104-
await expect(reportModal.modalTitle).not.toBeVisible();
99+
await reportModal.cancelReport();
105100
});
106101
});
107102

@@ -116,18 +111,13 @@ test.describe.serial('report message', () => {
116111
});
117112

118113
await test.step('report message as the other user', async () => {
114+
reportDescription = faker.lorem.sentence();
115+
119116
const adminHomeChannel = new HomeChannel(adminPage);
120117
await adminHomeChannel.sidenav.openChat(targetChannel);
121-
122118
await adminHomeChannel.content.openLastMessageMenu();
123119
await adminPage.getByRole('menuitem', { name: 'Report' }).click();
124-
125-
reportDescription = faker.lorem.sentence();
126-
await reportModal.inputReportDescription.fill(reportDescription);
127-
128-
await reportModal.btnSubmitReport.click();
129-
130-
await expect(adminPage.getByText('Report has been sent')).toBeVisible();
120+
await reportModal.submitReport(reportDescription);
131121
});
132122

133123
await test.step('verify report in moderation console', async () => {

packages/i18n/src/locales/af.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,7 @@
17911791
"Reply": "antwoord",
17921792
"ReplyTo": "Antwoord op",
17931793
"Report_Abuse": "Rapporteer misbruik",
1794-
"Report_exclamation_mark": "Rapporteer!",
17951794
"Report_sent": "Verslag gestuur",
1796-
"Report_this_message_question_mark": "Rapporteer hierdie boodskap?",
17971795
"Reporting": "verslagdoening",
17981796
"Require_all_tokens": "Vereis alle tokens",
17991797
"Require_any_token": "Vereis enige teken",
@@ -2337,7 +2335,6 @@
23372335
"Wednesday": "Woensdag",
23382336
"Welcome": "Welkom <em>%s</em>.",
23392337
"Welcome_to_the": "Welkom by die",
2340-
"Why_do_you_want_to_report_question_mark": "Hoekom wil jy rapporteer?",
23412338
"Worldwide": "wêreldwyd",
23422339
"Would_you_like_to_return_the_inquiry": "Wil jy die navraag terugbesorg?",
23432340
"Yes": "Ja",
@@ -2370,7 +2367,6 @@
23702367
"You_need_to_type_in_your_password_in_order_to_do_this": "U moet u wagwoord invoer om dit te kan doen!",
23712368
"You_need_to_type_in_your_username_in_order_to_do_this": "Jy moet jou gebruikersnaam tik om dit te doen!",
23722369
"You_need_to_verifiy_your_email_address_to_get_notications": "Jy moet jou e-pos adres verifieer om kennisgewings te kry",
2373-
"You_need_to_write_something": "Jy moet iets skryf!",
23742370
"You_should_inform_one_url_at_least": "U moet ten minste een URL definieer.",
23752371
"You_should_name_it_to_easily_manage_your_integrations": "U moet dit noem om u integrasies maklik te bestuur.",
23762372
"You_will_not_be_able_to_recover": "Jy sal nie hierdie boodskap kan herstel nie!",

packages/i18n/src/locales/ar.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,9 +3073,7 @@
30733073
"Report": "إبلاغ",
30743074
"Report_Abuse": "الإبلاغ عن إساءة",
30753075
"Report_Number": "رقم الإبلاغ",
3076-
"Report_exclamation_mark": "إبلاغ!",
30773076
"Report_sent": "تم إرسال الإبلاغ",
3078-
"Report_this_message_question_mark": "هل أبلغ عن هذه الرسالة؟",
30793077
"Reporting": "يتم الإبلاغ الآن",
30803078
"Request": "طلب",
30813079
"Request_comment_when_closing_conversation": "طلب التعليق عند إغلاق المحادثة",
@@ -4083,7 +4081,6 @@
40834081
"When_is_the_chat_busier?": "متى تكون الدردشة مشغولة جدًا؟",
40844082
"Where_are_the_messages_being_sent?": "أين يتم إرسال الرسائل؟",
40854083
"Why_did_you_chose__score__": "لماذا اخترت {{score}}؟",
4086-
"Why_do_you_want_to_report_question_mark": "لماذا تريد الإبلاغ؟",
40874084
"Will_Appear_In_From": "سيظهر في عنوان \"من\": رأس رسائل البريد الإلكتروني التي ترسلها.",
40884085
"Will_be_available_here_after_saving": "سيكون متاحًا هنا بعد الحفظ.",
40894086
"Without_priority": "من دون أولوية",
@@ -4131,7 +4128,6 @@
41314128
"You_need_to_type_in_your_password_in_order_to_do_this": "تحتاج إلى كتابة كلمة المرور الخاصة بك للقيام بذلك!",
41324129
"You_need_to_type_in_your_username_in_order_to_do_this": "تحتاج إلى كتابة اسم المستخدم الخاص بك للقيام بذلك!",
41334130
"You_need_to_verifiy_your_email_address_to_get_notications": "تحتاج إلى التحقق من عنوان بريدك الإلكتروني لتلقي الإشعارات",
4134-
"You_need_to_write_something": "تحتاج إلى كتابة شيء!",
41354131
"You_reached_the_maximum_number_of_guest_users_allowed_by_your_license": "لقد وصلت إلى الحد الأقصى لعدد المستخدمين الضيوف الذي يسمح به ترخيصك.",
41364132
"You_should_inform_one_url_at_least": "يجب عليك تحديد عنوان URL واحد على الأقل.",
41374133
"You_should_name_it_to_easily_manage_your_integrations": "يجب عليك تسميته لإدارة عمليات التكامل بسهولة.",

packages/i18n/src/locales/az.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,7 @@
17921792
"Reply": "Cavab ver",
17931793
"ReplyTo": "Cavab vermək",
17941794
"Report_Abuse": "Şikayət et",
1795-
"Report_exclamation_mark": "Hesabat!",
17961795
"Report_sent": "Hesabat göndərildi",
1797-
"Report_this_message_question_mark": "Bu mesajı bildirin?",
17981796
"Reporting": "Hesabat",
17991797
"Require_all_tokens": "Bütün simvollar tələb olunur",
18001798
"Require_any_token": "Hər hansı mö'cüzə tələb et",
@@ -2338,7 +2336,6 @@
23382336
"Wednesday": "Çərşənbə günü",
23392337
"Welcome": "Xoş gəldiniz <em>%s</em>.",
23402338
"Welcome_to_the": "Xoş gəlmisiniz",
2341-
"Why_do_you_want_to_report_question_mark": "Niyə hesabat vermək istəyirsiniz?",
23422339
"Worldwide": "Dünya miqyasında",
23432340
"Would_you_like_to_return_the_inquiry": "Sorğu qaytarmaq istəyirsinizmi?",
23442341
"Yes": "Bəli",
@@ -2371,7 +2368,6 @@
23712368
"You_need_to_type_in_your_password_in_order_to_do_this": "Bunun üçün parolunuzu yazmalısınız!",
23722369
"You_need_to_type_in_your_username_in_order_to_do_this": "Bunu etmək üçün istifadəçi adınızı yazmalısınız!",
23732370
"You_need_to_verifiy_your_email_address_to_get_notications": "Bildirişlər almaq üçün e-poçt ünvanınızı təsdiqləməlisiniz",
2374-
"You_need_to_write_something": "Bir şey yazmalısan!",
23752371
"You_should_inform_one_url_at_least": "Ən azı bir URL müəyyən etməlisiniz.",
23762372
"You_should_name_it_to_easily_manage_your_integrations": "İnteqrasiyanı asanlıqla idarə etmək üçün onu adlandırmalısınız.",
23772373
"You_will_not_be_able_to_recover": "Bu mesajı bərpa edə bilməzsiniz!",

packages/i18n/src/locales/be-BY.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,9 +1810,7 @@
18101810
"Reply": "адказаць",
18111811
"ReplyTo": "Адказваць на",
18121812
"Report_Abuse": "Паведаміць аб парушэннях",
1813-
"Report_exclamation_mark": "Даклад!",
18141813
"Report_sent": "Справаздача адпраўлены",
1815-
"Report_this_message_question_mark": "Паведаміць пра гэта паведамленні?",
18161814
"Reporting": "справаздачнасці",
18171815
"Require_all_tokens": "Патрабаваць, каб усе маркеры",
18181816
"Require_any_token": "Патрабаваць любы маркер",
@@ -2358,7 +2356,6 @@
23582356
"Wednesday": "серада",
23592357
"Welcome": "Сардэчна запрашаем <em>%s</em>.",
23602358
"Welcome_to_the": "Сардэчна запрашаем у",
2361-
"Why_do_you_want_to_report_question_mark": "Чаму вы хочаце паведаміць?",
23622359
"Worldwide": "сусветнай",
23632360
"Would_you_like_to_return_the_inquiry": "Вы хочаце, каб вярнуць запыт?",
23642361
"Yes": "Да",
@@ -2391,7 +2388,6 @@
23912388
"You_need_to_type_in_your_password_in_order_to_do_this": "Вы павінны ўвесці свой пароль для таго, каб зрабіць гэта!",
23922389
"You_need_to_type_in_your_username_in_order_to_do_this": "Вы павінны ўвесці імя карыстальніка для таго, каб зрабіць гэта!",
23932390
"You_need_to_verifiy_your_email_address_to_get_notications": "Вы павінны пацвердзіць свой адрас электроннай пошты для атрымання апавяшчэнняў",
2394-
"You_need_to_write_something": "Вы павінны напісаць што-небудзь!",
23952391
"You_should_inform_one_url_at_least": "Вы павінны вызначыць прынамсі адзін URL.",
23962392
"You_should_name_it_to_easily_manage_your_integrations": "Вы павінны назваць яго лёгка кіраваць інтэграцый.",
23972393
"You_will_not_be_able_to_recover": "Вы не зможаце аднавіць гэта паведамленне!",

packages/i18n/src/locales/bg.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,9 +1788,7 @@
17881788
"Reply": "Отговор",
17891789
"ReplyTo": "Отговаряте на",
17901790
"Report_Abuse": "Съобщете за злоупотреба",
1791-
"Report_exclamation_mark": "Доклад!",
17921791
"Report_sent": "Отчетът е изпратен",
1793-
"Report_this_message_question_mark": "Подайте сигнал за това съобщение?",
17941792
"Reporting": "Докладване",
17951793
"Require_all_tokens": "Изисквайте всички жетони",
17961794
"Require_any_token": "Изискайте всеки символ",
@@ -2333,7 +2331,6 @@
23332331
"Wednesday": "Сряда",
23342332
"Welcome": "Добре дошли <em>%s</em>.",
23352333
"Welcome_to_the": "Добре дошли в",
2336-
"Why_do_you_want_to_report_question_mark": "Защо искате да подадете сигнал?",
23372334
"Worldwide": "В световен мащаб",
23382335
"Would_you_like_to_return_the_inquiry": "Искате ли да върнете запитването?",
23392336
"Yes": "Да",
@@ -2365,7 +2362,6 @@
23652362
"You_need_to_type_in_your_password_in_order_to_do_this": "За да направите това, трябва да въведете паролата си!",
23662363
"You_need_to_type_in_your_username_in_order_to_do_this": "Трябва да въведете потребителското си име, за да направите това!",
23672364
"You_need_to_verifiy_your_email_address_to_get_notications": "Трябва да потвърдите имейл адреса си, за да получавате известия",
2368-
"You_need_to_write_something": "Трябва да напишете нещо!",
23692365
"You_should_inform_one_url_at_least": "Трябва да определите поне един URL адрес.",
23702366
"You_should_name_it_to_easily_manage_your_integrations": "Трябва да го наименувате, за да управлявате лесно интегрирането си.",
23712367
"You_will_not_be_able_to_recover": "Няма да можете да възстановите това съобщение!",

packages/i18n/src/locales/bs.i18n.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,9 +1785,7 @@
17851785
"Reply": "Odgovor",
17861786
"ReplyTo": "Odgovarati na",
17871787
"Report_Abuse": "Prijavi zlostavljanje",
1788-
"Report_exclamation_mark": "Izvješće!",
17891788
"Report_sent": "Izvješće je poslano",
1790-
"Report_this_message_question_mark": "Prijavi ovu poruku?",
17911789
"Reporting": "Prijava",
17921790
"Require_all_tokens": "Zahtijevaj sve oznake",
17931791
"Require_any_token": "Zahtijevaj token",
@@ -2330,7 +2328,6 @@
23302328
"Wednesday": "Srijeda",
23312329
"Welcome": "Dobro došao/la <em>%s</em>.",
23322330
"Welcome_to_the": "Dobro došli na",
2333-
"Why_do_you_want_to_report_question_mark": "Zašto želite prijaviti?",
23342331
"Worldwide": "širom svijeta",
23352332
"Would_you_like_to_return_the_inquiry": "Želite li vratiti upit?",
23362333
"Yes": "Da",
@@ -2363,7 +2360,6 @@
23632360
"You_need_to_type_in_your_password_in_order_to_do_this": "Morate upisati svoju lozinku kako biste to učinili!",
23642361
"You_need_to_type_in_your_username_in_order_to_do_this": "Morate upisati svoje korisničko ime kako bi se to učinili!",
23652362
"You_need_to_verifiy_your_email_address_to_get_notications": "Morate verificirati vašu e-mail adresu kako bi dobivali obavijesti",
2366-
"You_need_to_write_something": "Morate napisati nešto!",
23672363
"You_should_inform_one_url_at_least": "Trebali bi definirati barem jedan URL.",
23682364
"You_should_name_it_to_easily_manage_your_integrations": "Trebali bi imenovati integracije kako bi lakše njima upravljali.",
23692365
"You_will_not_be_able_to_recover": "Nećeš moći vratiti ovu poruku!",

0 commit comments

Comments
 (0)