fix: fix some dialog state issues (#1203)

* fix: fix some dialog state issues

fixes #1202

* fix console logs
This commit is contained in:
Nolan Lawson 2019-05-09 20:34:45 -07:00 committed by GitHub
parent db0f5bf237
commit b7b9758445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 21 deletions

View File

@ -4,6 +4,7 @@
{title} {title}
shrinkWidthToFit={true} shrinkWidthToFit={true}
background="var(--main-bg)" background="var(--main-bg)"
on:show="onShow()"
> >
<form class="copy-dialog-form"> <form class="copy-dialog-form">
<input value={text} <input value={text}
@ -47,13 +48,6 @@
export default { export default {
oncreate () { oncreate () {
onCreateDialog.call(this) onCreateDialog.call(this)
let { text } = this.get()
let { input } = this.refs
// double raf is to work around a11y-dialog trying to set the input
doubleRAF(() => {
input.focus()
input.setSelectionRange(0, text.length)
})
}, },
methods: { methods: {
show, show,
@ -63,6 +57,15 @@
copyFromInput(input) copyFromInput(input)
toast.say('Copied to clipboard') toast.say('Copied to clipboard')
this.close() this.close()
},
onShow () {
let { text } = this.get()
let { input } = this.refs
// double raf is to work around a11y-dialog trying to set the input
doubleRAF(() => {
input.focus()
input.setSelectionRange(0, text.length)
})
} }
}, },
data: () => ({ data: () => ({

View File

@ -4,6 +4,7 @@
{title} {title}
shrinkWidthToFit={true} shrinkWidthToFit={true}
background="var(--main-bg)" background="var(--main-bg)"
on:show="onShow()"
> >
<div class="emoji-container" {style} ref:container > <div class="emoji-container" {style} ref:container >
{#if loaded} {#if loaded}
@ -104,7 +105,6 @@
define({ 'emoji-mart': Picker }) define({ 'emoji-mart': Picker })
} }
this.set({ loaded: true }) this.set({ loaded: true })
this.focusIfNecessary()
} catch (error) { } catch (error) {
this.set({ error }) // should never happen, but you never know this.set({ error }) // should never happen, but you never know
} }
@ -168,6 +168,9 @@
insertEmoji(realm, emoji) insertEmoji(realm, emoji)
this.close() this.close()
}, },
onShow () {
this.focusIfNecessary()
},
focusIfNecessary () { focusIfNecessary () {
let { autoFocus } = this.get() let { autoFocus } = this.get()
if (!autoFocus) { if (!autoFocus) {

View File

@ -4,6 +4,7 @@
background="var(--muted-modal-bg)" background="var(--muted-modal-bg)"
muted="true" muted="true"
className="media-modal-dialog" className="media-modal-dialog"
on:show="onShow()"
> >
<div class="media-container"> <div class="media-container">
<ul class="media-scroll" ref:scroller> <ul class="media-scroll" ref:scroller>
@ -199,24 +200,12 @@
import debounce from 'lodash-es/debounce' import debounce from 'lodash-es/debounce'
import times from 'lodash-es/times' import times from 'lodash-es/times'
import { smoothScroll, hasNativeSmoothScroll } from '../../../_utils/smoothScroll' import { smoothScroll, hasNativeSmoothScroll } from '../../../_utils/smoothScroll'
import { doubleRAF } from '../../../_utils/doubleRAF'
import { store } from '../../../_store/store' import { store } from '../../../_store/store'
export default { export default {
oncreate () { oncreate () {
onCreateDialog.call(this) onCreateDialog.call(this)
this.onScroll = debounce(this.onScroll.bind(this), 50, { leading: false, trailing: true }) this.onScroll = debounce(this.onScroll.bind(this), 50, { leading: false, trailing: true })
let { scrolledItem } = this.get()
if (scrolledItem) {
doubleRAF(() => {
this.scrollToItem(scrolledItem, false)
this.setupScroll()
})
} else {
this.setupScroll()
}
}, },
ondestroy () { ondestroy () {
this.teardownScroll() this.teardownScroll()
@ -287,6 +276,17 @@
this.scrollToItem(scrolledItem - 1, true) this.scrollToItem(scrolledItem - 1, true)
} }
}, },
onShow () {
let { scrolledItem } = this.get()
if (scrolledItem) {
requestAnimationFrame(() => {
this.scrollToItem(scrolledItem, false)
this.setupScroll()
})
} else {
this.setupScroll()
}
},
scrollToItem (scrolledItem, smooth) { scrollToItem (scrolledItem, smooth) {
this.set({ scrolledItem: scrolledItem }) this.set({ scrolledItem: scrolledItem })
let { length } = this.get() let { length } = this.get()
@ -302,6 +302,7 @@
smoothScroll(scroller, scrollLeft, true) smoothScroll(scroller, scrollLeft, true)
} }
} else { } else {
console.log('setting scrollLeft', scrollLeft)
scroller.scrollLeft = scrollLeft scroller.scrollLeft = scrollLeft
} }
}, },

View File

@ -227,6 +227,7 @@
document.body.classList.toggle('modal-open', true) document.body.classList.toggle('modal-open', true)
this._a11yDialog.show() this._a11yDialog.show()
this.set({ fadedIn: true }) this.set({ fadedIn: true })
this.fire('show')
}) })
}) })
}, },

View File

@ -147,7 +147,7 @@
export default { export default {
async oncreate () { async oncreate () {
onCreateDialog.apply(this) onCreateDialog.call(this)
let { account, status, reportMap } = this.get() let { account, status, reportMap } = this.get()
if (status) { if (status) {
reportMap[status.id] = true reportMap[status.id] = true