Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55ea9be

Browse files
authored
fix(AuthForm): use password input id for aria-controls (#5312)
1 parent 1e6242e commit 55ea9be

File tree

4 files changed

+44
-48
lines changed

4 files changed

+44
-48
lines changed

src/runtime/components/AuthForm.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const appConfig = useAppConfig() as AuthForm['AppConfig']
150150
151151
const formRef = useTemplateRef('formRef')
152152
const passwordVisibility = ref(false)
153+
const passwordRef = useTemplateRef('passwordRef')
153154
154155
// eslint-disable-next-line vue/no-dupe-keys
155156
const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.authForm || {}) })())
@@ -274,6 +275,7 @@ function omitFieldProps(field: F) {
274275
/>
275276
<UInput
276277
v-else-if="field.type === 'password'"
278+
ref="passwordRef"
277279
v-model="state[field.name]"
278280
:class="ui.password({ class: props.ui?.password })"
279281
v-bind="(omitFieldProps(field) as AuthFormInputField<'password'>)"
@@ -287,7 +289,7 @@ function omitFieldProps(field: F) {
287289
:icon="passwordVisibility ? appConfig.ui.icons.eyeOff : appConfig.ui.icons.eye"
288290
:aria-label="passwordVisibility ? t('authForm.hidePassword') : t('authForm.showPassword')"
289291
:aria-pressed="passwordVisibility"
290-
aria-controls="password"
292+
:aria-controls="passwordRef?.[0]?.inputRef?.id"
291293
@click="passwordVisibility = !passwordVisibility"
292294
/>
293295
</template>

test/components/AuthForm.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,9 @@ describe('AuthForm', () => {
5757
providers: [{ label: 'Google', icon: 'i-simple-icons-google' }],
5858
separator: 'or',
5959
submit: { label: 'Submit' }
60-
6160
}
6261
})
6362

64-
expect(await axe(wrapper.element, {
65-
rules: {
66-
// The passwordVisibility button has an invalid aria-controls value - it need to point to the id of the password input not its name.
67-
'aria-valid-attr-value': { enabled: false }
68-
}
69-
})).toHaveNoViolations()
63+
expect(await axe(wrapper.element)).toHaveNoViolations()
7064
})
7165
})

0 commit comments

Comments
 (0)