Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-months-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Restores initial focus on description input in file upload modal for improved usability
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Modal, Box, Field, FieldGroup, FieldLabel, FieldRow, FieldError, TextInput, Button } from '@rocket.chat/fuselage';
import { useAutoFocus, useMergedRefs } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useTranslation, useSetting } from '@rocket.chat/ui-contexts';
import fileSize from 'filesize';
import type { ReactElement, ComponentProps } from 'react';
Expand Down Expand Up @@ -75,6 +76,13 @@ const FileUploadModal = ({
const fileUploadFormId = useId();
const fileNameField = useId();
const fileDescriptionField = useId();
const autoFocusRef = useAutoFocus();

const { ref, ...descriptionField } = register('description', {
validate: (value) => isDescriptionValid(value || ''),
});

const descriptionRef = useMergedRefs(ref, autoFocusRef);

return (
<Modal
Expand All @@ -86,7 +94,7 @@ const FileUploadModal = ({
<Box display='flex' flexDirection='column' height='100%'>
<Modal.Header>
<Modal.Title id={`${fileUploadFormId}-title`}>{t('FileUpload')}</Modal.Title>
<Modal.Close tabIndex={-1} onClick={onClose} />
<Modal.Close onClick={onClose} />
</Modal.Header>
<Modal.Content>
<Box display='flex' maxHeight='x360' w='full' justifyContent='center' alignContent='center' mbe={16}>
Expand Down Expand Up @@ -115,9 +123,8 @@ const FileUploadModal = ({
<FieldRow>
<TextInput
id={fileDescriptionField}
{...register('description', {
validate: (value) => isDescriptionValid(value || ''),
})}
ref={descriptionRef}
{...descriptionField}
error={errors.description?.message}
aria-invalid={errors.description ? 'true' : 'false'}
aria-describedby={`${fileDescriptionField}-error`}
Expand Down
16 changes: 9 additions & 7 deletions apps/meteor/tests/e2e/file-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ test.describe.serial('file-upload', () => {
expect((await api.post('/channels.delete', { roomName: targetChannel })).status()).toBe(200);
});

test('expect successfully cancel upload', async () => {
test('should successfully cancel upload', async () => {
await poHomeChannel.content.dragAndDropTxtFile();
await poHomeChannel.content.btnModalCancel.click();
await expect(poHomeChannel.content.modalFilePreview).not.toBeVisible();
});

test('expect send file not show modal', async () => {
test('should not display modal when clicking in send file', async () => {
await poHomeChannel.content.dragAndDropTxtFile();
await poHomeChannel.content.btnModalConfirm.click();
await expect(poHomeChannel.content.modalFilePreview).not.toBeVisible();
});

test('expect send file with name/description updated', async () => {
test('should send file with name/description updated', async () => {
await poHomeChannel.content.dragAndDropTxtFile();
await expect(poHomeChannel.content.descriptionInput).toBeFocused();

await poHomeChannel.content.descriptionInput.fill('any_description');
await poHomeChannel.content.fileNameInput.fill('any_file1.txt');
await poHomeChannel.content.btnModalConfirm.click();
Expand All @@ -49,7 +51,7 @@ test.describe.serial('file-upload', () => {
await expect(poHomeChannel.content.lastMessageFileName).toContainText('any_file1.txt');
});

test('expect send lst file succesfully', async () => {
test('should send lst file successfully', async () => {
await poHomeChannel.content.dragAndDropLstFile();
await poHomeChannel.content.descriptionInput.fill('lst_description');
await poHomeChannel.content.btnModalConfirm.click();
Expand All @@ -58,7 +60,7 @@ test.describe.serial('file-upload', () => {
await expect(poHomeChannel.content.lastMessageFileName).toContainText('lst-test.lst');
});

test('expect send drawio (unknown media type) file succesfully', async ({ page }) => {
test('should send drawio (unknown media type) file successfully', async ({ page }) => {
await page.reload();
await poHomeChannel.content.sendFileMessage('diagram.drawio');
await poHomeChannel.content.descriptionInput.fill('drawio_description');
Expand All @@ -68,7 +70,7 @@ test.describe.serial('file-upload', () => {
await expect(poHomeChannel.content.lastMessageFileName).toContainText('diagram.drawio');
});

test('expect not to send drawio file (unknown media type) when the default media type is blocked', async ({ api, page }) => {
test('should not to send drawio file (unknown media type) when the default media type is blocked', async ({ api, page }) => {
await setSettingValueById(api, 'FileUpload_MediaTypeBlackList', 'application/octet-stream');

await page.reload();
Expand Down Expand Up @@ -96,7 +98,7 @@ test.describe('file-upload-not-member', () => {
expect((await api.post('/channels.delete', { roomName: targetChannel })).status()).toBe(200);
});

test('expect not be able to upload if not a member', async () => {
test('should not be able to upload if not a member', async () => {
await poHomeChannel.content.dragAndDropTxtFile();
await expect(poHomeChannel.content.modalFilePreview).not.toBeVisible();
});
Expand Down
Loading