dbgate/packages/web/src/elements/SearchInput.svelte

43 lines
750 B
Svelte
Raw Normal View History

2021-02-20 16:57:53 +00:00
<script lang="ts">
import keycodes from '../utility/keycodes';
2021-11-13 15:19:42 +00:00
import _ from 'lodash';
2021-02-20 10:53:00 +00:00
export let placeholder;
export let value;
2021-11-15 17:54:02 +00:00
$: searchValue = value || '';
2021-11-13 15:19:42 +00:00
export let isDebounced = false;
let domInput;
function handleKeyDown(e) {
if (e.keyCode == keycodes.escape) {
value = '';
}
}
2021-11-13 15:19:42 +00:00
const debouncedSet = _.debounce(x => (value = x), 500);
2021-02-20 10:53:00 +00:00
</script>
<input
type="text"
{placeholder}
2021-11-13 15:19:42 +00:00
value={searchValue}
on:input={e => {
if (isDebounced) debouncedSet(domInput.value);
else value = domInput.value;
}}
on:keydown={handleKeyDown}
bind:this={domInput}
on:focus={e => domInput.select()}
/>
2021-02-20 10:53:00 +00:00
<style>
input {
flex: 1;
min-width: 10px;
width: 10px;
border: none;
}
</style>