Skip to content

Commit 92dddea

Browse files
0x0dr1ymtorromeo
authored andcommitted
fix(Inputs): reactive validated prop
1 parent 258ddfd commit 92dddea

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/core/src/components/TextInput.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</template>
3939

4040
<script lang="ts" setup>
41-
import { type Ref, ref, computed, type InputHTMLAttributes, getCurrentInstance } from 'vue';
41+
import { type Ref, ref, computed, toRefs, type InputHTMLAttributes, getCurrentInstance } from 'vue';
4242
import { useChildrenTracker } from '../use';
4343
import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
4444
import { useInputValidation, type InputValidateState } from '../input';
@@ -116,6 +116,7 @@ const ouiaProps = useOUIAProps({id: props.ouiaId, safe: props.ouiaSafe});
116116
const input: Ref<HTMLInputElement | undefined> = ref();
117117
const hasStatusIcon = computed(() => !props.noStatusIcon && ['success', 'error', 'warning'].includes(effectiveValidated.value));
118118
119+
const { validated } = toRefs(props);
119120
const {
120121
value,
121122
effectiveValidated,
@@ -128,7 +129,7 @@ const {
128129
} = useInputValidation({
129130
inputElement: input,
130131
autoValidate: props.autoValidate,
131-
validated: props.validated,
132+
validated: validated,
132133
});
133134
134135
useChildrenTracker(FormInputsKey, getCurrentInstance()?.proxy);

packages/core/src/components/Textarea.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<script lang="ts" setup>
4242
import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
4343
44-
import { computed, ref, onMounted, type TextareaHTMLAttributes, type Ref, getCurrentInstance } from 'vue';
44+
import { computed, ref, onMounted, toRefs, type TextareaHTMLAttributes, type Ref, getCurrentInstance } from 'vue';
4545
import { useInputValidation } from '../input';
4646
import { useChildrenTracker } from '../use';
4747
import { FormGroupInputsKey, FormInputsKey } from './Form/common';
@@ -114,6 +114,7 @@ const ouiaProps = useOUIAProps({id: props.ouiaId, safe: props.ouiaSafe});
114114
const input: Ref<HTMLTextAreaElement | undefined> = ref();
115115
const hasStatusIcon = computed(() => ['success', 'error', 'warning'].includes(effectiveValidated.value));
116116
117+
const { validated } = toRefs(props);
117118
const {
118119
value,
119120
effectiveValidated,
@@ -126,7 +127,7 @@ const {
126127
} = useInputValidation({
127128
inputElement: input,
128129
autoValidate: props.autoValidate,
129-
validated: props.validated,
130+
validated: validated,
130131
customCheckValidity: checkValidity,
131132
});
132133

packages/core/src/input.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ export function useInputValidation({
1212
customCheckValidity,
1313
}: {
1414
autoValidate: '' | 'blur' | 'input' | 'change' | 'enter' | boolean;
15-
validated?: InputValidateState | null;
15+
validated?: Ref<InputValidateState | undefined>;
1616
inputElement?: MaybeRef<InputElement | undefined>;
1717
customCheckValidity?: () => boolean;
1818
}) {
1919
const instance = getCurrentInstance()?.proxy;
2020

2121
const innerValidated: Ref<InputValidateState> = ref('default');
22-
const effectiveValidated = computed(() => validated ?? innerValidated.value);
22+
const effectiveValidated = computed(() => validated?.value ?? innerValidated.value);
2323
watch(effectiveValidated, () => instance?.$emit('update:validated', effectiveValidated.value));
2424

2525
const value = useManagedProp('modelValue', '');

0 commit comments

Comments
 (0)