Skip to content

Commit

Permalink
Add hints to input components
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswainwright-mt committed Dec 9, 2024
1 parent 5896482 commit 94a8271
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
9 changes: 4 additions & 5 deletions components/GovDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
<div :class="`govuk-form-group ${props.context.state.invalid &&
props.context.messages.rule_required &&
props.context.messages.rule_required.visible
? 'govuk-form-group--error'
: ''
}`">
? 'govuk-form-group--error' : '' }`"
>
<label class="govuk-label govuk-label--m" :for="id">
{{ label }}
</label>
<div id="event-name-hint" class="govuk-hint">
<div :id="`${id}_hint`" class="govuk-hint" v-if="help">
{{ help }}
</div>
<p v-if="props.context.state.invalid" class="govuk-error-message" :data-testid="`${id}_error`">
Expand All @@ -41,7 +40,7 @@
@input="handleInput"
:value="mounted ? props.context._value : ''"
:data-testid="id"
:aria-describedby="props.context.state.invalid ? `${id}_error` : ''"
:aria-describedby="props.context.state.invalid ? `${id}_error` : help ? `${id}_hint` : ''"
>
<option v-for="key in Object.keys(options)" :value="key">
{{ options[key] }}
Expand Down
8 changes: 6 additions & 2 deletions components/GovInputInt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
const {
id,
node: { name },
label
label,
help
} = props.context;
const { mounted } = useMounted();
Expand All @@ -26,6 +27,9 @@
<label class="govuk-label govuk-label--m" :for="id">
{{ label }}
</label>
<div :id="`${id}_hint`" class="govuk-hint" v-if="help">
{{ help }}
</div>
<p v-if="props.context.state.invalid" class="govuk-error-message" :data-testid="`${id}_error`">
<span class="govuk-visually-hidden">Error:</span> {{ props.context.messages.rule_required?.value }}
</p>
Expand All @@ -38,7 +42,7 @@
type="number"
:value="mounted ? props.context._value : ''"
:data-testid="id"
:aria-describedby="props.context.state.invalid ? `${id}_error` : ''"
:aria-describedby="props.context.state.invalid ? `${id}_error` : help ? `${id}_hint` : ''"
/>
</div>
</div>
Expand Down
18 changes: 11 additions & 7 deletions components/GovInputMeters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
const {
id,
node: { name },
label
label,
help
} = props.context;
const { mounted } = useMounted();
Expand All @@ -18,14 +19,17 @@
</script>
<template>
<div :class="`govuk-form-group ${props.context.state.invalid &&
props.context.messages.rule_required &&
props.context.messages.rule_required.visible
? 'govuk-form-group--error'
: ''
}`">
props.context.messages.rule_required &&
props.context.messages.rule_required.visible
? 'govuk-form-group--error'
: ''}`"
>
<label class="govuk-label govuk-label--m" :for="id">
{{ label }}
</label>
<div :id="`${id}_hint`" class="govuk-hint" v-if="help">
{{ help }}
</div>
<p v-if="props.context.state.invalid" class="govuk-error-message" :data-testid="`${id}_error`">
<span class="govuk-visually-hidden">Error:</span> {{ props.context.messages.rule_required?.value }}
</p>
Expand All @@ -38,7 +42,7 @@
type="number"
:value="mounted ? props.context._value : ''"
:data-testId="id"
:aria-describedby="props.context.state.invalid ? `${id}_error` : ''"
:aria-describedby="props.context.state.invalid ? `${id}_error` : help ? `${id}_hint` : ''"
/>
<div class="govuk-input__suffix" aria-hidden="true">m2</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions components/GovRadios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@

<template>
<div :class="`govuk-form-group ${props.context.state.invalid ? 'govuk-form-group--error' : ''}`">
<fieldset :id="id" class="govuk-fieldset" :aria-describedby="props.context.state.invalid ? `${id}_error` : ''">
<fieldset
:id="id"
class="govuk-fieldset"
:aria-describedby="props.context.state.invalid ? `${id}_error` : help ? `${id}_hint` : ''"
>
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
{{ label }}
</legend>
<div id="event-name-hint" class="govuk-hint">
<div :id="`${id}_hint`" class="govuk-hint" v-if="help">
{{ help }}
</div>
<p v-if="props.context.state.invalid" class="govuk-error-message" :data-testid="`${id}_error`">
Expand All @@ -41,10 +45,14 @@
:checked="mounted ? props.context._value == key : false"
@change="handleInput"
:data-testid="`${id}_${key}`"
:aria-describedby="typeof options[key] === 'object' ? `${id}_${key}_hint` : ''"
/>
<label class="govuk-label govuk-radios__label" :for="`${id}_${key}`">
{{ options[key] }}
{{ typeof options[key] === 'object' ? options[key].label : options[key] }}
</label>
<div :id="`${id}_${key}_hint`" class="govuk-hint govuk-radios__hint" v-if="(typeof options[key] === 'object')">
{{ options[key].hint }}
</div>
</div>
</div>
</fieldset>
Expand Down
7 changes: 6 additions & 1 deletion formkit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import GovDropdown from './components/GovDropdown.vue';
import GovInputInt from './components/GovInputInt.vue';
import GovInputMeters from './components/GovInputMeters.vue';

type GovRadioOption = {
label: string;
hint?: string;
}

// Enable TypeScript support for custom inputs
declare module '@formkit/inputs' {
interface FormKitInputProps<Props extends FormKitInputs<Props>> {
'govRadios': {
type: 'govRadios',
options: FormKitOptionsProp
options: Record<string, string | GovRadioOption>
},
'govButton': {
type: 'govButton'
Expand Down
14 changes: 11 additions & 3 deletions pages/dwelling-details/general-specifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
id="levelOfShelter"
name="levelOfShelter"
validation="required"
help="Exposure level of the dwelling"
/>
<FormKit
type="govInputInt"
Expand All @@ -111,8 +112,14 @@
<FormKit
type="govRadios"
:options="{
seperateTempControl: 'Separate temperature control',
seperateTempAndTimeControl: 'Separate temperature and time control ',
seperateTempControl: {
label: 'Separate temperature control',
hint: 'Both living and rest of dwelling zones follow the same schedule but have different temperature set points.'
},
seperateTempAndTimeControl: {
label: 'Separate temperature and time control',
hint: 'Each zone has heating schedule and temperature set points.'
},
}"
label="Heating control type"
id="heatingControlType"
Expand All @@ -132,7 +139,7 @@
/>
<FormKit
type="govRadios"
:options="{
:options="{
mainsWater: 'Mains water',
headerTank: 'Header tank',
}"
Expand All @@ -147,6 +154,7 @@
id="numOfADFWetRooms"
name="numOfADFWetRooms"
validation="required | number"
help="Rooms used for domestic activities such as kitchen and bathroom that create a large amount of airborne moisture."
/>
<FormKit type="govButton" label="Save and continue" />
</FormKit>
Expand Down

0 comments on commit 94a8271

Please sign in to comment.