Skip to content

Commit fc54bac

Browse files
committed
feat: add disabled prop for <spring> element
1 parent bc863ef commit fc54bac

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.ja.md

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ requestAnimationFrame(() => {
123123
- `spring-style`: アニメーションさせるスタイルオブジェクト
124124
- `bounce`
125125
- `duration`
126+
- `disabled`
126127

127128
```vue
128129
<script setup>

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ It renders a native HTML element as same tag name as the property name (e.g. `<s
123123
- `spring-style`: Style object to be animated
124124
- `bounce`
125125
- `duration`
126+
- `disabled`
126127

127128
```vue
128129
<script setup>

src/vue/spring-element.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const createSpringElement = (tagName: string) => {
1111
},
1212
bounce: Number,
1313
duration: Number,
14+
disabled: Boolean,
1415
},
1516

1617
setup(props, { slots }) {
@@ -20,6 +21,7 @@ const createSpringElement = (tagName: string) => {
2021
return {
2122
bounce: props.bounce,
2223
duration: props.duration,
24+
disabled: props.disabled,
2325
}
2426
},
2527
)

test/vue/spring-element.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,39 @@ describe('Spring Element', () => {
8787
expect(mockController.setOptions).toHaveBeenCalledWith({
8888
bounce: 0.2,
8989
duration: 800,
90+
disabled: false,
9091
})
9192
expect(mockController.setStyle).toHaveBeenCalledWith({ opacity: 0 })
9293
})
94+
95+
test('disable animation when disabled prop is true', async () => {
96+
const root = document.createElement('div')
97+
const app = createApp({
98+
template: `
99+
<springp :spring-style="springStyle" disabled>
100+
Hello
101+
</springp>
102+
`,
103+
104+
components: {
105+
springp: spring.p!,
106+
},
107+
108+
setup() {
109+
const springStyle = ref({ opacity: 1 })
110+
return {
111+
springStyle,
112+
}
113+
},
114+
})
115+
const vm: any = app.mount(root)
116+
expect(vm.$el.style.opacity).toBe('1')
117+
118+
vm.springStyle.opacity = 0
119+
await nextTick()
120+
expect(mockController.setStyle).toHaveBeenCalledWith(
121+
{ opacity: 0 },
122+
{ animate: false },
123+
)
124+
})
93125
})

0 commit comments

Comments
 (0)