Skip to content

Commit

Permalink
workaround autofocus bug in svelte-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jan 14, 2025
1 parent 228ea09 commit 08ba2f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions frontend/viewer/src/lib/entry-editor/inputs/CrdtTextField.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';
import CrdtField from './CrdtField.svelte';
import { TextField } from 'svelte-ux';
import { TextField, autoFocus as autoFocusFunc } from 'svelte-ux';
export let value: string | number | null | undefined;
export let unsavedChanges = false;
Expand All @@ -18,15 +18,18 @@
if (label && labelElem) labelElem.setAttribute('title', label);
}
</script>

<CrdtField on:change bind:value bind:unsavedChanges let:editorValue let:save let:onEditorValueChange viewMergeButtonPortal={append}>
<TextField
on:change={(e) => onEditorValueChange(e.detail.inputValue)}
on:blur={(e) => {if (e.target) save()}}
actions={(el) => { addTitleToLabel(el); return []; }}
actions={(el) => {
addTitleToLabel(el);
// autofocus requires a delay otherwise it won't work in a dialog
// also we can't use the autofocus attribute because of https://github.com/techniq/svelte-ux/issues/532
return autofocus ? [autoFocusFunc(el, {delay: 5})] : [];
}}
value={editorValue}
disabled={readonly}
autofocus={autofocus}
class="ws-field gap-2 text-right"
classes={{ root: `${editorValue ? '' : 'empty'} ${readonly ? 'readonly' : ''}`, input: 'field-input', container: 'field-container' }}
{label}
Expand Down

0 comments on commit 08ba2f2

Please sign in to comment.