Skip to content

Commit ac7136d

Browse files
committed
fix(VLazy): properly show transition on activation
also fixed bad class and onObserve process
1 parent ba99a45 commit ac7136d

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

packages/vuetify/src/components/VLazy/VLazy.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,41 @@ export default mixins(Toggleable).extend({
4444

4545
methods: {
4646
genContent () {
47-
if (!this.isActive) return undefined
48-
4947
const slot = getSlot(this)
5048

5149
/* istanbul ignore if */
5250
if (!this.transition) return slot
5351

52+
const children = []
53+
54+
if (this.isActive) children.push(slot)
55+
5456
return this.$createElement('transition', {
5557
props: { name: this.transition },
56-
}, slot)
58+
}, children)
5759
},
58-
onObserve (entries: IntersectionObserverEntry[]) {
60+
onObserve (
61+
entries: IntersectionObserverEntry[],
62+
observer: IntersectionObserver,
63+
isIntersecting: boolean,
64+
) {
5965
if (this.isActive) return
6066

61-
this.isActive = Boolean(entries.find(entry => entry.isIntersecting))
67+
this.isActive = isIntersecting
6268
},
6369
},
6470

6571
render (h): VNode {
6672
return h('div', {
67-
staticClass: 'v-observe',
73+
staticClass: 'v-lazy',
6874
attrs: this.$attrs,
6975
directives: [{
7076
name: 'intersect',
7177
value: {
7278
handler: this.onObserve,
7379
options: this.options,
7480
},
75-
}] as any,
81+
}],
7682
on: this.$listeners,
7783
style: this.styles,
7884
}, [this.genContent()])

packages/vuetify/src/components/VLazy/__tests__/VLazy.spec.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,18 @@ describe('VLazy.ts', () => {
5151

5252
expect(wrapper.vm.isActive).toBeFalsy()
5353

54-
wrapper.vm.onObserve([
55-
{ isIntersecting: false },
56-
{ isIntersecting: false },
57-
{ isIntersecting: false },
58-
] as IntersectionObserverEntry[])
54+
const entries = [] as IntersectionObserverEntry[]
55+
const observer = {} as IntersectionObserver
56+
57+
wrapper.vm.onObserve(entries, observer, false)
5958

6059
expect(wrapper.vm.isActive).toBeFalsy()
6160

62-
wrapper.vm.onObserve([
63-
{ isIntersecting: false },
64-
{ isIntersecting: false },
65-
{ isIntersecting: true },
66-
] as IntersectionObserverEntry[])
61+
wrapper.vm.onObserve(entries, observer, true)
6762

6863
expect(wrapper.vm.isActive).toBeTruthy()
6964

70-
wrapper.vm.onObserve([
71-
{ isIntersecting: false },
72-
{ isIntersecting: false },
73-
{ isIntersecting: false },
74-
] as IntersectionObserverEntry[])
65+
wrapper.vm.onObserve(entries, observer, false)
7566

7667
expect(wrapper.vm.isActive).toBeTruthy()
7768
})

packages/vuetify/src/components/VLazy/__tests__/__snapshots__/VLazy.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`VLazy.ts should conditionally render content 1`] = `
4-
<div class="v-observe">
4+
<div class="v-lazy">
55
</div>
66
`;
77

88
exports[`VLazy.ts should conditionally render content 2`] = `
9-
<div class="v-observe">
9+
<div class="v-lazy">
1010
<div>
1111
foobar
1212
</div>

0 commit comments

Comments
 (0)