Skip to content

Commit fe87885

Browse files
authored
[bugfix] Collapse: flick in safari (youzan#3686)
1 parent e08bea7 commit fe87885

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/collapse-item/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ export default createComponent({
6060
this.inited = true;
6161
}
6262

63-
raf(() => {
63+
// Use raf: flick when opened in safari
64+
// Use nextTick: closing animation failed when set `user-select: none`
65+
const nextTick = expanded ? this.$nextTick : raf;
66+
67+
nextTick(() => {
6468
const { content, wrapper } = this.$refs;
6569
if (!content || !wrapper) {
6670
return;
6771
}
6872

69-
const { clientHeight } = content;
70-
if (clientHeight) {
71-
const contentHeight = `${clientHeight}px`;
73+
const { offsetHeight } = content;
74+
if (offsetHeight) {
75+
const contentHeight = `${offsetHeight}px`;
7276
wrapper.style.height = expanded ? 0 : contentHeight;
7377
raf(() => {
7478
wrapper.style.height = expanded ? contentHeight : 0;
@@ -96,7 +100,7 @@ export default createComponent({
96100
if (!this.expanded) {
97101
this.show = false;
98102
} else {
99-
this.$refs.wrapper.style.height = null;
103+
this.$refs.wrapper.style.height = '';
100104
}
101105
}
102106
},

src/collapse/test/index.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ test('lazy render collapse content', async () => {
127127
const titles = wrapper.findAll('.van-collapse-item__title');
128128

129129
titles.at(1).trigger('click');
130-
await later(50);
131-
132130
wrapper.vm.content = 'content';
133131
expect(wrapper).toMatchSnapshot();
134132
});

0 commit comments

Comments
 (0)