Skip to content

Commit c9a1284

Browse files
committed
feat(TextInput): Use the aria-errormessage to associate the error message with the input
1 parent 2ccb564 commit c9a1284

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/components/TextInput/TextInput.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,6 @@ This component will take up the full width of the parent component by default. Y
206206

207207
This component uses native HTML behaviour for `<input />` elements. This means that it will be keyboard navigable and screen reader friendly out of the box.
208208

209-
`aria-describedby` is added to the `<input />` element when the `description` and/or the `error` slots are used to associate this content with the input.
209+
`aria-describedby` is added to the `<input />` element when the `description` slot is used to associate this content with the input.
210+
211+
`aria-errormessage` is added to the `<input />` element when the `error` slot is used to associate this content with the input.

src/components/TextInput/TextInput.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe('TextInput', () => {
293293
// Assert
294294
expect(wrapper.find('.j-textinput__error').exists()).toBe(true);
295295
expect(wrapper.find('.j-textinput__error').html()).toContain('This is an error message');
296-
expect(wrapper.find('input').attributes('aria-describedby')).toContain('test-id-error');
296+
expect(wrapper.find('input').attributes('aria-errormessage')).toContain('test-id-error');
297297
});
298298

299299
it('renders a description message', () => {

src/components/TextInput/TextInput.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
:type="type"
1313
:value="modelValue"
1414
:aria-invalid="status === 'error' ? 'true' : status === 'success' ? 'false' : undefined"
15-
:aria-describedby="[$slots.error ? `${id}-error` : '', $slots.description ? `${id}-description` : ''].filter(Boolean).join(' ') || undefined"
15+
:aria-errormessage="$slots.error ? `${id}-error` : undefined"
16+
:aria-describedby="$slots.description ? `${id}-description` : undefined"
1617
@input="emit('update:modelValue', ($event.target as HTMLInputElement).value)"
1718
/>
1819
<span v-if="status" class="j-textinput__validation-icon" aria-hidden="true"><template v-if="status === 'error'">✘</template><template v-if="status === 'success'">✔</template></span>

0 commit comments

Comments
 (0)