File size: 1,092 Bytes
6e856a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<script lang="ts">
	export let value = '';
	export let minRows = 1;
	export let maxRows: null | number = null;
	export let placeholder = '';
	export let autofocus = false;

	$: minHeight = `${1 + minRows * 1.5}em`;
	$: maxHeight = maxRows ? `${1 + maxRows * 1.5}em` : `auto`;

	function handleKeydown(event: KeyboardEvent) {
		// submit on enter
		if (event.key === 'Enter' && !event.shiftKey) {
			event.preventDefault();
			// @ts-ignore - requestSubmit is not in the DOM typings
			event.target?.form?.requestSubmit();
		}
	}
</script>

<div class="relative w-full">
	<pre
		class="invisible py-3"
		aria-hidden="true"
		style="min-height: {minHeight}; max-height: {maxHeight}">{value + '\n'}</pre>

	<textarea
		tabindex="0"
		rows="1"
		class="absolute m-0 w-full h-full top-0 resize-none border-0 bg-transparent p-3 focus:ring-0 focus-visible:ring-0 dark:bg-transparent outline-none scrollbar"
		bind:value
		on:keydown={handleKeydown}
		{placeholder}
		{autofocus}
	/>
</div>

<style>
	pre,
	textarea {
		font-family: inherit;
		box-sizing: border-box;
		line-height: 1.5;
	}
</style>