-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make content more navigable and accessible #16
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,31 +3,33 @@ import { t } from '../../i18n/server'; | |
import Base from '../../layouts/base.astro'; | ||
import { absUrl } from '../../lib/util'; | ||
import TextRaw from '../TextRaw.astro'; | ||
import RadioForm from '../RadioForm.astro'; | ||
|
||
interface Props { | ||
token: string; | ||
complainantIsUserOfApp: boolean | null; | ||
} | ||
|
||
const { token } = Astro.props; | ||
const { token, complainantIsUserOfApp } = Astro.props; | ||
const isChecked = (p: string) => | ||
(complainantIsUserOfApp === true && p === 'yes') || (complainantIsUserOfApp === false && p === 'no'); | ||
--- | ||
|
||
<Base title={t('complaint-landing-askIsUserOfApp', 'heading')}> | ||
<p> | ||
<TextRaw scope="complaint-landing-askIsUserOfApp" id="question" /> | ||
</p> | ||
|
||
<div class="col66 col100-mobile"> | ||
<div class="radio-group radio-group-vertical radio-group-padded"> | ||
{ | ||
(['yes', 'no'] as const).map((p) => ( | ||
<form class="radio-wrapper" method="POST" action={absUrl(`/p/${token}/complain/askIsUserOfApp`)}> | ||
<input type="hidden" name="answer" value={p} /> | ||
<button type="submit" class="radio-label"> | ||
{t('common', p)} | ||
</button> | ||
</form> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
<RadioForm | ||
actionUrl={absUrl(`/p/${token}/complain/askIsUserOfApp/answer`)} | ||
options={(['yes', 'no'] as const).reduce( | ||
(agg, p) => | ||
Object.assign(agg, { | ||
[p]: t('common', p), | ||
}), | ||
{}, | ||
)} | ||
Comment on lines
+25
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean… I love a good |
||
value={complainantIsUserOfApp === null ? null : complainantIsUserOfApp ? 'yes' : 'no'} | ||
idPrefix="askIsUserOfApp" | ||
/> | ||
</Base> |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||||
--- | ||||||||
import { t } from '../i18n/server'; | ||||||||
|
||||||||
interface Props { | ||||||||
actionUrl: string; | ||||||||
idPrefix: string; | ||||||||
options: Record<string, string>; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
value: string | null | undefined; | ||||||||
} | ||||||||
|
||||||||
const { idPrefix, actionUrl, options, value } = Astro.props; | ||||||||
--- | ||||||||
|
||||||||
<div class="col66 col100-mobile"> | ||||||||
<div class="radio-group radio-group-vertical radio-group-padded"> | ||||||||
<form method="POST" id={`${idPrefix}-form`} action={actionUrl} class="astro-radio-form"> | ||||||||
{ | ||||||||
Object.keys(options).map((option) => ( | ||||||||
<div class="radio-wrapper"> | ||||||||
<input | ||||||||
id={`${idPrefix}-radio-${option}`} | ||||||||
type="radio" | ||||||||
name="answer" | ||||||||
class="form-element" | ||||||||
value={option} | ||||||||
checked={option === value} | ||||||||
required="true" | ||||||||
/> | ||||||||
<label class={`radio-label `} for={`${idPrefix}-radio-${option}`}> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
{options[option]} | ||||||||
</label> | ||||||||
</div> | ||||||||
)) | ||||||||
} | ||||||||
<button type="submit" class="button sr-only">{t('common', 'continue')}</button> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also needs to be visible to users with JS disabled. |
||||||||
</form> | ||||||||
</div> | ||||||||
</div> | ||||||||
|
||||||||
<script> | ||||||||
const forms = document.getElementsByClassName('astro-radio-form') as HTMLCollectionOf<HTMLFormElement>; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this run for every form on the page, causing multiple event handlers to be registered if there are multiple forms? You know the ID of 'your' form, you only need to add it to that one. |
||||||||
|
||||||||
for (const form of forms) { | ||||||||
const inputs = form.querySelectorAll('div.radio-wrapper'); | ||||||||
|
||||||||
// The "click" event is also triggered by chnage events for radio buttons (https://www.w3.org/TR/2012/WD-html5-20121025/content-models.html#interactive-content) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
// Because of that, we use `mouseup` here, to specifically only check for actual clicks | ||||||||
for (const input of inputs) | ||||||||
input.addEventListener('mouseup', (e) => { | ||||||||
if ((e as MouseEvent).button === 0) form.submit(); | ||||||||
}); | ||||||||
} | ||||||||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused.