From 6e16a5122f134ca991205c03c0dd8628288e4b08 Mon Sep 17 00:00:00 2001 From: Jonas Metzener Date: Tue, 1 Nov 2022 11:05:37 +0100 Subject: [PATCH] feat(a11y): add aria invalid and describedby attributes on validation Closes #48 --- addon/components/validated-input.hbs | 16 ++++++++++++---- addon/components/validated-input.js | 9 +++++++++ addon/components/validated-input/error.hbs | 3 ++- addon/components/validated-input/hint.hbs | 1 + .../validated-input/types/checkbox-group.hbs | 2 ++ .../validated-input/types/checkbox.hbs | 2 ++ .../validated-input/types/radio-group.hbs | 2 ++ .../app/components/permanent-custom-hint.hbs | 2 +- .../components/validated-form-test.js | 10 ++++++++++ 9 files changed, 41 insertions(+), 6 deletions(-) diff --git a/addon/components/validated-input.hbs b/addon/components/validated-input.hbs index 89b1a77d..05934102 100644 --- a/addon/components/validated-input.hbs +++ b/addon/components/validated-input.hbs @@ -21,11 +21,11 @@ }} {{#if @hint}} - + {{/if}} {{#if (and this.showValidity this.errors)}} - + {{/if}} {{else}} {{/if}} \ No newline at end of file diff --git a/addon/components/validated-input.js b/addon/components/validated-input.js index 56cf21fa..848e2b5f 100644 --- a/addon/components/validated-input.js +++ b/addon/components/validated-input.js @@ -1,5 +1,6 @@ import { action, set, get } from "@ember/object"; import { guidFor } from "@ember/object/internals"; +import { isEmpty } from "@ember/utils"; import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; @@ -21,6 +22,14 @@ import passedOrDefault from "ember-validated-form/passed-or-default"; export default class ValidatedInputComponent extends Component { inputId = guidFor(this); + get errorId() { + return `${this.inputId}-error`; + } + + get hintId() { + return !isEmpty(this.args.hint) ? `${this.inputId}-hint` : null; + } + @tracked dirty; @tracked required; @tracked type; diff --git a/addon/components/validated-input/error.hbs b/addon/components/validated-input/error.hbs index e50487ed..587ecd02 100644 --- a/addon/components/validated-input/error.hbs +++ b/addon/components/validated-input/error.hbs @@ -1,9 +1,10 @@ {{#if (macroCondition (macroGetOwnConfig "isUikit"))}} - + {{yield}}{{this.errorString}} {{else}} {{option.label}} @@ -29,6 +30,7 @@ id="{{@inputId}}-{{i}}" disabled={{@disabled}} {{on "input" (fn this.onUpdate option.key)}} + ...attributes /> @@ -31,6 +32,7 @@ id="{{@inputId}}-{{i}}" disabled={{@disabled}} {{on "input" (fn this.onUpdate option.key)}} + ...attributes />