Skip to content

Commit

Permalink
Autofocus lexeme form when new entry dialog opens (#1368)
Browse files Browse the repository at this point in the history
* Autofocus lexeme form when new entry dialog opens

---------

Co-authored-by: Kevin Hahn <[email protected]>
  • Loading branch information
rmunn and hahn-kev authored Jan 17, 2025
1 parent 1570a3f commit 8dd28ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
export let wsType: WritingSystemSelection;
export let value: IMultiString;
export let readonly: boolean = false;
export let autofocus: boolean = false;
let unsavedChanges: Record<string, boolean> = {};
let currentView = useCurrentView();
Expand All @@ -31,11 +32,12 @@
<div class="multi-field field" class:collapse-field={collapse} class:empty class:hidden={!$currentView.fields[id].show} style:grid-area={id}>
<FieldTitle {id} {name} />
<div class="fields">
{#each writingSystems as ws (ws.wsId)}
{#each writingSystems as ws, idx (ws.wsId)}
<CrdtTextField
on:change={() => dispatch('change', { value })}
bind:value={value[ws.wsId]}
bind:unsavedChanges={unsavedChanges[ws.wsId]}
autofocus={autofocus && (idx == 0)}
label={collapse ? undefined : ws.abbreviation}
labelPlacement={collapse ? undefined : 'left'}
placeholder={collapse ? ws.abbreviation : undefined}
Expand Down
11 changes: 8 additions & 3 deletions frontend/viewer/src/lib/entry-editor/inputs/CrdtTextField.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<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;
export let label: string | undefined = undefined;
export let labelPlacement: ComponentProps<TextField>['labelPlacement'] = undefined;
export let placeholder: string | undefined = undefined;
export let readonly: boolean | undefined = undefined;
export let autofocus: boolean = false;
let append: HTMLElement;
// Labels don't always fit (beause WS's can be long and ugly), so a title might be important sometimes
Expand All @@ -17,12 +18,16 @@
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}
class="ws-field gap-2 text-right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<MultiFieldEditor on:change={() => dispatch('change', {entry})}
bind:value={entry.lexemeForm}
{readonly}
autofocus={modalMode}
id="lexemeForm"
wsType="vernacular"/>

Expand Down

0 comments on commit 8dd28ee

Please sign in to comment.