Skip to content

Commit d26be4e

Browse files
committed
improve scrolling to message
1 parent 5ddfb1d commit d26be4e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/components/SuggestionForm.svelte

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
2-
import { scroll_into_view } from '$lib/client/utils'
32
import { faCheckCircle, faWarning } from '@fortawesome/free-solid-svg-icons'
3+
import { tick } from 'svelte'
44
import Fa from 'svelte-fa'
55
66
let title = $state('')
@@ -34,11 +34,18 @@
3434
error = 'Failed to fetch API'
3535
} finally {
3636
sending = false
37+
await tick()
38+
section?.scrollIntoView({
39+
block: 'end',
40+
behavior: 'smooth',
41+
})
3742
}
3843
}
44+
45+
let section = $state<HTMLElement | null>(null)
3946
</script>
4047

41-
<section>
48+
<section bind:this={section}>
4249
<h2>Suggestion Form</h2>
4350

4451
<p class="hint">
@@ -67,14 +74,14 @@
6774
</form>
6875

6976
{#if error}
70-
<p class="error" {@attach scroll_into_view}>
77+
<p class="error">
7178
<Fa icon={faWarning} />
7279
Error: {error}
7380
</p>
7481
{/if}
7582

7683
{#if url}
77-
<p {@attach scroll_into_view}>
84+
<p>
7885
<Fa icon={faCheckCircle} />
7986
Your suggestion has been created as a
8087
<a href={url} target="_blank">GitHub issue</a>. We will have a look at it!
@@ -85,6 +92,8 @@
8592
<style>
8693
section {
8794
margin-top: 4rem;
95+
padding-bottom: 1rem;
96+
margin-bottom: -1rem;
8897
}
8998
9099
.error {

src/lib/client/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,3 @@ export function string_to_color(str: string): string {
2626
const h = hash % 360
2727
return `hsl(${h}, 80%, 50%)`
2828
}
29-
30-
export const scroll_into_view: Attachment = (element) => {
31-
element.scrollIntoView({ block: 'end', behavior: 'smooth' })
32-
}

0 commit comments

Comments
 (0)