Skip to content

Commit 5449c4a

Browse files
committed
moved scrollToBottom to its own function; replaced setTimeout with nextTick based behavior
1 parent 0e72963 commit 5449c4a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/components/ScreenIdentifiers.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</template>
5555

5656
<script lang="ts">
57-
import { defineComponent, ref } from 'vue'
57+
import { defineComponent, nextTick, ref } from 'vue'
5858
import Stepper from 'components/Stepper.vue'
5959
import StepperActions from 'components/StepperActions.vue'
6060
import IdentifierCardEditing from 'components/IdentifierCardEditing.vue'
@@ -73,7 +73,7 @@ export default defineComponent({
7373
setup () {
7474
const { identifiers, setIdentifiers } = useCff()
7575
const editingId = ref(-1)
76-
const addIdentifier = () => {
76+
const addIdentifier = async () => {
7777
const newIdentifier: IdentifierType = {
7878
type: 'doi',
7979
value: '',
@@ -82,17 +82,19 @@ export default defineComponent({
8282
const newIdentifiers = [...identifiers.value, newIdentifier]
8383
setIdentifiers(newIdentifiers)
8484
editingId.value = newIdentifiers.length - 1
85-
setTimeout(() => {
86-
// FIXME shouldn't have to use a timeout but it seems the DOM doesn't update in time
87-
document.getElementsByClassName('bottom')[0].scrollIntoView({ behavior: 'smooth' })
88-
}, 100)
85+
// await the DOM update that resulted from updating the identifiers list
86+
await nextTick()
87+
scrollToBottom()
8988
}
9089
const removeIdentifier = () => {
9190
const newIdentifiers = [...identifiers.value]
9291
newIdentifiers.splice(editingId.value, 1)
9392
setIdentifiers(newIdentifiers)
9493
editingId.value = -1
9594
}
95+
const scrollToBottom = () => {
96+
document.getElementsByClassName('bottom')[0].scrollIntoView({ behavior: 'smooth' })
97+
}
9698
const setIdentifierDescriptionField = (field: keyof IdentifierType, value: string) => {
9799
const identifier = { ...identifiers.value[editingId.value] }
98100
identifier.description = value

0 commit comments

Comments
 (0)