Skip to content

Commit 25beabd

Browse files
committed
feat(Textarea): component is generic over v-model number modifier
1 parent f83e6a6 commit 25beabd

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

packages/core/src/components/Textarea.vue

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,8 @@
3838
</span>
3939
</template>
4040

41-
<script lang="ts" setup>
42-
import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
43-
44-
import { computed, onMounted, toRefs, type TextareaHTMLAttributes, getCurrentInstance, useTemplateRef } from 'vue';
45-
import { useInputValidation } from '../input';
46-
import { useChildrenTracker } from '../use';
47-
import { FormGroupInputsKey, FormInputsKey } from './Form/common';
48-
import { useOUIAProps, type OUIAProps } from '../helpers/ouia';
49-
import PfFormControlIcon from './FormControlIcon.vue';
50-
51-
defineOptions({
52-
name: 'PfTextarea',
53-
inheritAttrs: false,
54-
});
55-
56-
export interface Props extends OUIAProps, /* @vue-ignore */ Omit<TextareaHTMLAttributes, 'value' | 'aria-invalid'> {
41+
<script lang="ts">
42+
export interface Props<N extends boolean = false> extends OUIAProps, /* @vue-ignore */ Omit<TextareaHTMLAttributes, 'value' | 'aria-invalid'> {
5743
/** Flag to show if the text area is disabled. */
5844
disabled?: boolean;
5945
@@ -76,7 +62,7 @@ export interface Props extends OUIAProps, /* @vue-ignore */ Omit<TextareaHTMLAtt
7662
/** Value of the text area. */
7763
modelValue?: string | number | null;
7864
modelModifiers?: {
79-
number?: boolean;
65+
number?: N;
8066
trim?: boolean;
8167
lazy?: boolean;
8268
};
@@ -95,8 +81,24 @@ export interface Props extends OUIAProps, /* @vue-ignore */ Omit<TextareaHTMLAtt
9581
/** Maximum width */
9682
maxWidth?: string;
9783
}
84+
</script>
85+
86+
<script lang="ts" setup generic="N extends boolean = false">
87+
import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
88+
89+
import { computed, onMounted, toRefs, type TextareaHTMLAttributes, getCurrentInstance, useTemplateRef } from 'vue';
90+
import { useInputValidation } from '../input';
91+
import { useChildrenTracker } from '../use';
92+
import { FormGroupInputsKey, FormInputsKey } from './Form/common';
93+
import { useOUIAProps, type OUIAProps } from '../helpers/ouia';
94+
import PfFormControlIcon from './FormControlIcon.vue';
95+
96+
defineOptions({
97+
name: 'PfTextarea',
98+
inheritAttrs: false,
99+
});
98100
99-
const props = withDefaults(defineProps<Props>(), {
101+
const props = withDefaults(defineProps<Props<N>>(), {
100102
resizeOrientation: 'both',
101103
autoValidate: true,
102104
modelValue: undefined,
@@ -110,8 +112,8 @@ defineEmits<{
110112
(name: 'input', event: Event): void;
111113
(name: 'invalid', event: Event): void;
112114
(name: 'keyup', event: KeyboardEvent): void;
113-
(name: 'update:modelValue'): void;
114-
(name: 'update:validated'): void;
115+
(name: 'update:modelValue', value: N extends true ? number : string): void;
116+
(name: 'update:validated', value: 'success' | 'warning' | 'error' | 'default'): void;
115117
}>();
116118
117119
const ouiaProps = useOUIAProps({id: props.ouiaId, safe: props.ouiaSafe});
@@ -132,7 +134,7 @@ const {
132134
} = useInputValidation({
133135
inputElement: input,
134136
autoValidate: props.autoValidate,
135-
validated: validated,
137+
validated,
136138
customCheckValidity: checkValidity,
137139
});
138140

0 commit comments

Comments
 (0)