Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofocus lexeme form when new entry dialog opens #1368

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading