Skip to content

Commit 6e8b041

Browse files
author
issayah
committed
Fix aria invalid form attribute incorrect values
1 parent 25bbe09 commit 6e8b041

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/components/BFormInput/BFormInput.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
</template>
2626

2727
<script lang="ts">
28-
import {InputType} from '../../types'
28+
import type {InputType} from '@/types'
2929
import {computed, defineComponent, PropType} from 'vue'
30-
import useFormInput, {COMMON_INPUT_PROPS} from '../../composables/useFormInput'
30+
import useFormInput, {COMMON_INPUT_PROPS} from '@/composables/useFormInput'
3131
3232
const allowedTypes = [
3333
'text',
@@ -74,7 +74,9 @@ export default defineComponent({
7474
}
7575
})
7676
77-
const localType = computed(() => (allowedTypes.includes(props.type) ? props.type : 'text'))
77+
const localType = computed<InputType>(() =>
78+
allowedTypes.includes(props.type) ? props.type : 'text'
79+
)
7880
7981
const {input, computedId, computedAriaInvalid, onInput, onChange, onBlur, focus, blur} =
8082
useFormInput(props, emit)

src/composables/useFormInput.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,26 @@ function useFormInput(props: Readonly<InputProps>, emit: InputEmitType) {
8181

8282
onActivated(handleAutofocus)
8383

84-
const computedAriaInvalid = computed(() => {
85-
if (props.ariaInvalid) {
86-
return props.ariaInvalid.toString()
84+
const computedAriaInvalid = computed<'grammar' | 'spelling' | boolean | undefined>(() => {
85+
if (props.state === false) {
86+
return true
8787
}
88-
return props.state === false ? 'true' : undefined
88+
if (props.state === true) {
89+
return undefined
90+
}
91+
if (typeof props.ariaInvalid === 'boolean') {
92+
if (props.ariaInvalid === false) {
93+
return undefined
94+
}
95+
return props.ariaInvalid
96+
}
97+
if (props.ariaInvalid === 'true') {
98+
return true
99+
}
100+
if (props.ariaInvalid === 'false') {
101+
return undefined
102+
}
103+
return props.ariaInvalid
89104
})
90105

91106
const onInput = (evt: Event) => {

0 commit comments

Comments
 (0)