Skip to content

Commit 9f0df8c

Browse files
committed
fix(InputText): Icons
1 parent 70b3aa9 commit 9f0df8c

File tree

1 file changed

+6
-38
lines changed

1 file changed

+6
-38
lines changed

Diff for: src/components/PrimeInputText.vue

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang='ts'>
2-
import { type PropType, computed } from 'vue'
2+
import type { PropType } from 'vue'
33
import type { FormKitFrameworkContext } from '@formkit/core'
44
55
import IconField from 'primevue/iconfield'
66
import InputIcon from 'primevue/inputicon'
77
import type { InputTextProps } from 'primevue/inputtext'
8-
import { useFormKitInput } from '../composables'
8+
import { useFormKitIcon, useFormKitInput } from '../composables'
99
1010
export interface FormKitPrimeInputTextProps {
1111
pt?: InputTextProps['pt']
@@ -24,27 +24,13 @@ const props = defineProps({
2424
})
2525
2626
const { styleClass, wrapperClass, handleInput, handleBlur } = useFormKitInput(props.context)
27-
28-
const hasIcon = computed(() => {
29-
if (props.context?.icon && props.context?.icon.length > 0)
30-
return true
31-
32-
return props.context?.attrs?.icon && props.context?.attrs?.icon.length > 0
33-
})
34-
35-
const icon = computed(() => {
36-
return props.context?.icon ?? props.context?.attrs?.icon
37-
})
38-
39-
const iconPosition = computed(() => {
40-
return props.context?.attrs?.iconPosition ?? undefined
41-
})
27+
const { hasIcon, icon, iconPosition } = useFormKitIcon(props.context)
4228
</script>
4329

4430
<template>
4531
<div :class="wrapperClass">
46-
<IconField v-if="hasIcon" :icon-position="iconPosition">
47-
<InputIcon :class="icon" />
32+
<IconField>
33+
<InputIcon v-if="hasIcon && iconPosition === 'left'" :class="icon" />
4834
<InputText
4935
:id="context.id"
5036
v-model="context._value"
@@ -63,25 +49,7 @@ const iconPosition = computed(() => {
6349
@input="handleInput"
6450
@blur="handleBlur"
6551
/>
52+
<InputIcon v-if="hasIcon && iconPosition === 'right'" :class="icon" />
6653
</IconField>
67-
<InputText
68-
v-else
69-
:id="context.id"
70-
v-model="context._value"
71-
v-bind="context?.attrs"
72-
:disabled="!!context?.disabled"
73-
:readonly="context?.attrs.readonly ?? false"
74-
:style="context?.attrs.style"
75-
:class="styleClass"
76-
:tabindex="context?.attrs.tabindex"
77-
:aria-label="context?.attrs.ariaLabel"
78-
:aria-labelledby="context?.attrs.ariaLabelledby"
79-
:placeholder="context.placeholder"
80-
:pt="context.pt"
81-
:pt-options="context.ptOptions"
82-
:unstyled="context.unstyled ?? false"
83-
@input="handleInput"
84-
@blur="handleBlur"
85-
/>
8654
</div>
8755
</template>

0 commit comments

Comments
 (0)