Skip to content
Open
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
21 changes: 21 additions & 0 deletions playwright/e2e/a11y-question-inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ test.describe('Accessibility: aria attributes on question inputs', () => {
await expect(page.locator('#q1_desc')).toContainText('Upload your file')
})

test('File question upload button has an accessible name', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')

await form.addQuestion(QuestionType.File)
const questions = await form.getQuestions()
await questions[0].fillTitle('My file question')

await topBar.toggleView(FormsView.View)

const question = page.getByRole('listitem', { name: /Question number 1/ })
await expect(
question.getByRole('button', { name: 'Upload a file' }),
).toBeVisible()
})

test('Color question with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
Expand Down
8 changes: 8 additions & 0 deletions src/components/Questions/QuestionFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
@input="onFileInput" />
</label>
<NcButton
:aria-label="uploadButtonLabel"
:disabled="
!readOnly || values.length >= maxAllowedFilesCount
"
Expand Down Expand Up @@ -268,6 +269,12 @@ export default defineComponent({
return extraSettings.value.maxAllowedFilesCount ?? 1
})

const uploadButtonLabel = computed<string>(() => {
return maxAllowedFilesCount.value > 1
? t('forms', 'Upload files')
: t('forms', 'Upload a file')
})

Comment on lines +272 to +277

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the n function for the translations here, that already handles plurals out of the box

const allowedFileExtensions = computed<string[]>(() => {
return extraSettings.value.allowedFileExtensions ?? []
})
Expand Down Expand Up @@ -532,6 +539,7 @@ export default defineComponent({
availableUnits,
uploadedFiles,
maxAllowedFilesCount,
uploadButtonLabel,
allowedFileExtensions,
allowedFileTypes,
allowedFileTypesLabel,
Expand Down
Loading