@@ -31,6 +31,7 @@ const props = withDefaults(
31
31
autosize? : boolean
32
32
autofocus? : boolean
33
33
monospace? : boolean
34
+ pasteHtml? : boolean
34
35
}>(),
35
36
{
36
37
value: ' ' ,
@@ -58,13 +59,14 @@ const props = withDefaults(
58
59
autosize: false ,
59
60
autofocus: false ,
60
61
monospace: false ,
62
+ pasteHtml: false ,
61
63
},
62
64
);
63
65
const emit = defineEmits ([' update:value' ]);
64
66
const value = useVModel (props , ' value' , emit );
65
67
const showPassword = ref (false );
66
68
67
- const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace } = toRefs (props );
69
+ const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace, pasteHtml } = toRefs (props );
68
70
69
71
const validation
70
72
= props .validation
@@ -81,6 +83,28 @@ const textareaRef = ref<HTMLTextAreaElement>();
81
83
const inputRef = ref <HTMLInputElement >();
82
84
const inputWrapperRef = ref <HTMLElement >();
83
85
86
+ interface HTMLElementWithValue {
87
+ value? : string
88
+ }
89
+
90
+ function onPasteInputHtml(evt : ClipboardEvent ) {
91
+ if (! pasteHtml .value ) {
92
+ return false ;
93
+ }
94
+
95
+ const target = (evt .target as HTMLElementWithValue );
96
+ if (! target ) {
97
+ return false ;
98
+ }
99
+ evt .preventDefault ();
100
+ const textHtmlData = evt .clipboardData ?.getData (' text/html' );
101
+ if (textHtmlData && textHtmlData !== ' ' ) {
102
+ value .value = textHtmlData ;
103
+ return true ;
104
+ }
105
+ return false ;
106
+ }
107
+
84
108
watch (
85
109
[value , autosize , multiline , inputWrapperRef , textareaRef ],
86
110
() => nextTick (() => {
@@ -171,6 +195,7 @@ defineExpose({
171
195
:autocorrect =" autocorrect ?? (rawText ? 'off' : undefined)"
172
196
:spellcheck =" spellcheck ?? (rawText ? false : undefined)"
173
197
:rows =" rows"
198
+ @paste =" onPasteInputHtml"
174
199
/>
175
200
176
201
<input
@@ -192,6 +217,7 @@ defineExpose({
192
217
:autocomplete =" autocomplete ?? (rawText ? 'off' : undefined)"
193
218
:autocorrect =" autocorrect ?? (rawText ? 'off' : undefined)"
194
219
:spellcheck =" spellcheck ?? (rawText ? false : undefined)"
220
+ @paste =" onPasteInputHtml"
195
221
>
196
222
197
223
<c-button v-if =" clearable && value" variant =" text" circle size =" small" @click =" value = ''" >
0 commit comments