Skip to content

Commit

Permalink
Improve form a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Oct 26, 2024
1 parent 9f6cc2d commit eb6987b
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions lang/en/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'form_subject_received' => 'Contact form received',
'form_subject_sent' => 'Contact form sent',
'form_success' => 'Thank you, we received your message and will contact you as soon as possible.',
'form_required' => 'Required',

// Consent banner
'consent_accept_all' => 'Accept all',
Expand Down
1 change: 1 addition & 0 deletions lang/nl/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'form_mail_from' => 'Statamic Peak Development',
'form_mail_greeting' => 'Beste',
'form_mail_logo' => 'http://statamic-peak.test/visuals/statamic-peak-logo.png',
'form_required' => 'Verplicht',
'form_mail_submitted' => 'Verzonden',
'form_mail_title' => 'Contactformulier',
'form_mail_url' => 'http://statamic-peak.test',
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"name": "lodash-es"
},
"resources/css/site.css": {
"file": "assets/site-DU7OtWCi.css",
"file": "assets/site-yiYUX_rW.css",
"src": "resources/css/site.css",
"isEntry": true
},
Expand Down
22 changes: 12 additions & 10 deletions resources/views/page_builder/_form.antlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h3 class="mb-2 leading-5 font-bold text-red-700">{{ trans:strings.form_error }}
{{ fields scope="field" }}
<template x-if="{{ show_field }}">
<div class="
flex flex-col
flex flex-col stack-1
{{ input_type == 'hidden' ?= 'hidden' }}
{{ switch(
(width == '25') => 'md:col-span-3',
Expand All @@ -69,16 +69,18 @@ <h3 class="mb-2 leading-5 font-bold text-red-700">{{ trans:strings.form_error }}
<label class="font-bold" for="{{ handle }}">
{{ trans :key="field:display" }}
{{ if validate | contains('required') || validate | contains('accepted') }}
<sup class="text-red-700">*</sup>
{{ /if }}

{{ if field:instructions && instructions_position != 'below' }}
{{ partial:typography/p class="mt-1 font-normal text-sm" content="{ trans :key="field:instructions" }" }}
<sup aria-label="{{ trans:strings.form_required }}" class="text-red-700">*</sup>
{{ /if }}
</label>

{{ if field:instructions && instructions_position != 'below' }}
<span id="{{ field:handle }}-instructions" class="text-sm">
{{ trans :key="field:instructions" }}
</span>
{{ /if }}
{{ /unless }}

<div class="mt-2 flex flex-col gap-y-2">
<div class="stack-space-2 flex flex-col stack-2">
{{ field:field }}

{{# Inline error. #}}
Expand All @@ -87,9 +89,9 @@ <h3 class="mb-2 leading-5 font-bold text-red-700">{{ trans:strings.form_error }}
</template>

{{ if field:instructions && instructions_position === 'below' }}
<p id="{{ field:handle }}-instructions">
{{ partial:typography/p as="span" class="text-sm" content="{ trans :key="field:instructions" }" }}
</p>
<span id="{{ field:handle }}-instructions" class="text-sm">
{{ trans :key="field:instructions" }}
</span>
{{ /if }}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
name="{{ handle }}[]"
multiple
{{ /if }}
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
>
<!-- End: /vendor/statamic/forms/fields/assets.antlers.html -->
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:aria-invalid="form.invalid('{{ handle }}')"
class="flex {{ inline ? 'gap-x-4' : 'flex-col gap-y-2' }}"
id="{{ handle }}"
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
>
{{ foreach:options as="value|label" }}
<label class="inline-flex items-baseline">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name="{{ handle }}"
type="{{ input_type ?? 'text' }}"
{{ placeholder ?= 'placeholder="{placeholder}"' }}
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
{{ character_limit ?= 'maxlength="{character_limit}"' }}
{{ autocomplete ?= 'autocomplete="{autocomplete}"' }}
{{ old ?= 'value="{old}"' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:aria-invalid="form.invalid('{{ handle }}')"
class="flex {{ inline ? 'gap-x-4' : 'flex-col gap-y-2' }}"
id="{{ handle }}"
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
>
{{ foreach:options as="value|label" }}
<label class="inline-flex items-baseline">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class="w-full rounded"
id="{{ handle }}"
name="{{ handle }}{{ multiple ?= "[]" }}"
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
{{ multiple ?= "multiple" }}
{{ autocomplete ?= 'autocomplete="{autocomplete}"' }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name="{{ handle }}"
rows="5"
{{ placeholder ?= 'placeholder="{placeholder}"' }}
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
{{ character_limit ?= 'maxlength="{character_limit}"' }}
{{ autocomplete ?= 'autocomplete="{autocomplete}"' }}
>{{ old }}</textarea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<label
class="inline-flex items-baseline"
:aria-invalid="form.invalid('{{ handle }}')"
{{ instructions_position == 'below' ?= 'aria-describedBy="{handle}-instructions"' }}
{{ instructions ?= 'aria-describedBy="{handle}-instructions"' }}
>
<input type="hidden" name="{{ handle }}" value="0">
<input
Expand Down

0 comments on commit eb6987b

Please sign in to comment.