Skip to content

Commit

Permalink
Focus editable text on edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 19, 2024
1 parent 3a40349 commit e060264
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Dates should be in`YYYY-MM-DD` format and versions are in [semantic versioning](
### Fixed

- Removed box shadow from inactive links.
- Focus editable text on edit.

### Maintained

Expand Down
6 changes: 6 additions & 0 deletions src/lib/EditableText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { PostgrestError } from '@supabase/supabase-js';
import Button from './Button.svelte';
import Loading from './Loading.svelte';
import { tick } from 'svelte';
interface Props {
text: string;
Expand All @@ -14,6 +15,7 @@
let editing = $state(false);
let revision = $state('');
let saving = $state(false);
let view = $state<HTMLInputElement | null>(null);
async function save() {
if (editing) {
Expand All @@ -30,6 +32,9 @@
} else {
editing = true;
revision = text;
await tick();
if (view) view.focus();
}
}
</script>
Expand All @@ -40,6 +45,7 @@
<!-- svelte-ignore a11y_autofocus -->
<input
type="text"
bind:this={view}
bind:value={revision}
disabled={saving}
style:width={revision.length + 2 + 'ch'}
Expand Down

0 comments on commit e060264

Please sign in to comment.