Skip to content

Commit deb861b

Browse files
committed
fix: a11y in ExportMessages and test locators
1 parent 8e3494a commit deb861b

2 files changed

Lines changed: 15 additions & 52 deletions

File tree

apps/meteor/client/views/room/contextualBar/ExportMessages/ExportMessages.tsx

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import type { SelectOption } from '@rocket.chat/fuselage';
2-
import {
3-
FieldError,
4-
Field,
5-
FieldLabel,
6-
FieldRow,
7-
TextAreaInput,
8-
TextInput,
9-
ButtonGroup,
10-
Button,
11-
Icon,
12-
FieldGroup,
13-
Select,
14-
InputBox,
15-
Callout,
16-
} from '@rocket.chat/fuselage';
2+
import { ButtonGroup, Button, Icon, InputBox, Callout } from '@rocket.chat/fuselage';
3+
import { FieldError, Field, FieldLabel, FieldRow, TextAreaInput, FieldGroup, Select, TextInput } from '@rocket.chat/fuselage-forms';
174
import { useAutoFocus } from '@rocket.chat/fuselage-hooks';
185
import { validateEmail } from '@rocket.chat/tools';
196
import {
@@ -197,13 +184,8 @@ const ExportMessages = () => {
197184
};
198185

199186
const formId = useId();
200-
const methodField = useId();
201-
const formatField = useId();
202-
const toUsersField = useId();
203187
const dateFromField = useId();
204188
const dateToField = useId();
205-
const additionalEmailsField = useId();
206-
const subjectField = useId();
207189

208190
return (
209191
<ContextualbarDialog aria-labelledby={`${formId}-title`}>
@@ -216,14 +198,13 @@ const ExportMessages = () => {
216198
<form ref={formFocus} tabIndex={-1} aria-labelledby={`${formId}-title`} id={formId} onSubmit={handleSubmit(handleExport)}>
217199
<FieldGroup>
218200
<Field>
219-
<FieldLabel htmlFor={methodField}>{t('Method')}</FieldLabel>
201+
<FieldLabel>{t('Method')}</FieldLabel>
220202
<FieldRow>
221203
<Controller
222204
name='type'
223205
control={control}
224206
render={({ field }) => (
225207
<Select
226-
id={methodField}
227208
data-testid='export-messages-method'
228209
{...field}
229210
placeholder={t('Type')}
@@ -235,7 +216,7 @@ const ExportMessages = () => {
235216
</FieldRow>
236217
</Field>
237218
<Field>
238-
<FieldLabel htmlFor={formatField}>{t('Output_format')}</FieldLabel>
219+
<FieldLabel>{t('Output_format')}</FieldLabel>
239220
<FieldRow>
240221
<Controller
241222
name='format'
@@ -254,7 +235,6 @@ const ExportMessages = () => {
254235
return (
255236
<Select
256237
{...field}
257-
id={formatField}
258238
data-testid='export-messages-output-format'
259239
disabled={type === 'email'}
260240
placeholder={t('Format')}
@@ -292,7 +272,7 @@ const ExportMessages = () => {
292272
{type === 'email' && (
293273
<>
294274
<Field>
295-
<FieldLabel htmlFor={toUsersField}>{t('To_users')}</FieldLabel>
275+
<FieldLabel>{t('To_users')}</FieldLabel>
296276
<FieldRow>
297277
<Controller
298278
name='toUsers'
@@ -308,32 +288,25 @@ const ExportMessages = () => {
308288
},
309289
},
310290
}}
311-
render={({ field: { value, onChange, onBlur, name } }) => (
291+
render={({ field: { value, onChange, onBlur, name, ...field } }) => (
312292
<UserAutoCompleteMultiple
313-
id={toUsersField}
293+
{...field}
314294
value={value}
315295
onChange={(value) => {
316296
onChange(value);
317297
clearErrors('additionalEmails');
318298
}}
319299
onBlur={onBlur}
320300
name={name}
321-
aria-label={t('To_users')}
322-
aria-describedby={`${toUsersField}-error`}
323-
aria-invalid={Boolean(errors?.toUsers?.message)}
324301
error={errors?.toUsers?.message}
325302
/>
326303
)}
327304
/>
328305
</FieldRow>
329-
{errors?.toUsers && (
330-
<FieldError role='alert' id={`${toUsersField}-error`}>
331-
{errors.toUsers.message}
332-
</FieldError>
333-
)}
306+
{errors?.toUsers && <FieldError>{errors.toUsers.message}</FieldError>}
334307
</Field>
335308
<Field>
336-
<FieldLabel htmlFor={additionalEmailsField}>{t('To_additional_emails')}</FieldLabel>
309+
<FieldLabel>{t('To_additional_emails')}</FieldLabel>
337310
<FieldRow>
338311
<Controller
339312
name='additionalEmails'
@@ -361,40 +334,30 @@ const ExportMessages = () => {
361334
},
362335
},
363336
}}
364-
render={({ field: { value, onChange, onBlur, name } }) => (
337+
render={({ field: { onChange, onBlur, ...field } }) => (
365338
<TextInput
366-
id={additionalEmailsField}
367-
value={value}
339+
{...field}
368340
onChange={(e) => {
369341
onChange(e);
370342
clearErrors('toUsers');
371343
}}
372344
onBlur={onBlur}
373-
name={name}
374345
placeholder={t('Email_Placeholder_any')}
375346
addon={<Icon name='mail' size='x20' />}
376-
aria-describedby={`${additionalEmailsField}-error`}
377-
aria-invalid={Boolean(errors?.additionalEmails?.message)}
378347
error={errors?.additionalEmails?.message}
379348
/>
380349
)}
381350
/>
382351
</FieldRow>
383-
{errors?.additionalEmails && (
384-
<FieldError role='alert' id={`${additionalEmailsField}-error`}>
385-
{errors.additionalEmails.message}
386-
</FieldError>
387-
)}
352+
{errors?.additionalEmails && <FieldError>{errors.additionalEmails.message}</FieldError>}
388353
</Field>
389354
<Field>
390-
<FieldLabel htmlFor={subjectField}>{t('Subject')}</FieldLabel>
355+
<FieldLabel>{t('Subject')}</FieldLabel>
391356
<FieldRow>
392357
<Controller
393358
name='subject'
394359
control={control}
395-
render={({ field }) => (
396-
<TextAreaInput rows={3} id={subjectField} {...field} addon={<Icon name='edit' size='x20' />} />
397-
)}
360+
render={({ field }) => <TextAreaInput rows={3} {...field} addon={<Icon name='edit' size='x20' />} />}
398361
/>
399362
</FieldRow>
400363
</Field>

apps/meteor/tests/e2e/page-objects/fragments/flextabs/export-messages-flextab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ExportMessagesFlexTab extends FlexTab {
5858
}
5959

6060
get inputUsers() {
61-
return this.root.getByLabel('To users');
61+
return this.root.getByRole('combobox', { name: 'To users' });
6262
}
6363

6464
get inputAdditionalEmails() {

0 commit comments

Comments
 (0)