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

feat(autofocus/keep-alive): refocus autofocus components on activate in keepAlive #12086

Merged
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
41 changes: 40 additions & 1 deletion ui/dev/src/pages/web-tests/panel-keep-alive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
</template>

<script>
import { QInput, QForm } from 'quasar'

export default {
components: {
KeepAliveTest: {
Expand All @@ -81,6 +83,12 @@ export default {
name: String
},

data () {
return {
text: 'input text sample'
}
},

created () {
this.log('created')
},
Expand All @@ -93,6 +101,14 @@ export default {
this.log('mounted')
},

activated () {
this.log('activated')
},

deactivated () {
this.log('deactivated')
},

beforeDestroy () {
this.log('beforeDestroy')
},
Expand All @@ -108,7 +124,30 @@ export default {
},

render (h) {
return h('div', [ 'keep alive test ' + this.name ])
return h('div', [
'keep alive test ' + this.name,
h(QForm, {
props: {
autofocus: true
}
}, [
h(QInput, {
class: 'q-my-md',
style: 'max-width: 300px',
props: {
value: this.text,
// autofocus: true,
outlined: true,
label: 'Input with autofocus'
},
on: {
input: val => {
this.text = val
}
}
})
])
])
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions ui/src/components/field/QField.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ export default Vue.extend({
this.autofocus === true && this.focus()
},

activated () {
if (this.shouldActivate !== true) { return }
this.autofocus === true && this.focus()
},

deactivated () {
this.shouldActivate = true
},

beforeDestroy () {
clearTimeout(this.focusoutTimer)
}
Expand Down
9 changes: 9 additions & 0 deletions ui/src/components/form/QForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export default Vue.extend({
this.autofocus === true && this.focus()
},

activated () {
if (this.shouldActivate !== true) { return }
this.autofocus === true && this.focus()
},

deactivated () {
this.shouldActivate = true
},

methods: {
validate (shouldFocus) {
const promises = []
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/infinite-scroll/QInfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default Vue.extend({
},

activated () {
if (this.__scrollTarget && this.__scrollPosition !== void 0) {
if (this.__scrollPosition !== void 0 && this.__scrollTarget) {
setScrollPosition(this.__scrollTarget, this.__scrollPosition)
}
},
Expand Down
4 changes: 3 additions & 1 deletion ui/src/components/scroll-area/QScrollArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,11 @@ export default Vue.extend({
},

activated () {
if (this.__scrollPosition === void 0) { return }

const scrollTarget = this.getScrollTarget()

if (scrollTarget !== void 0 && this.__scrollPosition !== void 0) {
if (scrollTarget !== void 0) {
setHorizontalScrollPosition(scrollTarget, this.__scrollPosition.left)
setVerticalScrollPosition(scrollTarget, this.__scrollPosition.top)
}
Expand Down
13 changes: 9 additions & 4 deletions ui/src/components/tabs/QTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,6 @@ export default Vue.extend({
}
},

activated () {
this.__recalculateScroll()
},

created () {
this.buffer = []

Expand All @@ -606,6 +602,15 @@ export default Vue.extend({
this.rtlHasScrollBug = rtlHasScrollBug()
},

activated () {
if (this.shouldActivate !== true) { return }
this.__recalculateScroll()
},

deactivated () {
this.shouldActivate = true
},

beforeDestroy () {
clearTimeout(this.bufferTimer)
clearTimeout(this.animateTimer)
Expand Down
6 changes: 6 additions & 0 deletions ui/src/mixins/virtual-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ export default {
},

activated () {
if (this.shouldActivate !== true) { return }

const scrollEl = this.__getVirtualScrollTarget()

if (this.prevScrollStart !== void 0 && scrollEl !== void 0 && scrollEl !== null && scrollEl.nodeType !== 8) {
Expand All @@ -705,6 +707,10 @@ export default {
}
},

deactivated () {
this.shouldActivate = true
},

beforeMount () {
this.__onVirtualScrollEvt = debounce(this.__onVirtualScrollEvt, this.$q.platform.is.ios === true ? 120 : 35)
this.__setVirtualScrollSize()
Expand Down