Skip to content

Commit

Permalink
fix(switch): abnormal loading animation when switching state (#2879)
Browse files Browse the repository at this point in the history
  • Loading branch information
XieZongChen authored May 4, 2022
1 parent e82cf29 commit 3ed47db
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## Pending

### Fixes

- Fix `n-menu`'s `dropdown-props` prop can't override `n-dropdown`'s `size` prop, closes [#2868](https://github.com/TuSimple/naive-ui/issues/2868).
- Fix `n-switch` abnormal loading animation when switching state, closes [#2870](https://github.com/TuSimple/naive-ui/issues/2870)

## 2.28.2

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## Pending

### Fixes

- 修复 `n-menu``dropdown-props` 无法覆盖 `n-dropdown``size` 属性,关闭 [#2868](https://github.com/TuSimple/naive-ui/issues/2868)
- 修复 `n-switch` 切换状态时 loading 动画异常,关闭 [#2870](https://github.com/TuSimple/naive-ui/issues/2870)

## 2.28.2

Expand Down
31 changes: 30 additions & 1 deletion src/switch/demos/enUS/loading.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,34 @@
</markdown>

<template>
<n-switch loading />
<n-space>
<n-switch loading />
<n-switch
:value="activeValue"
:loading="loading"
@update:value="handleChange"
/>
</n-space>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup () {
const activeValue = ref(false)
const loading = ref(false)
return {
activeValue,
loading,
handleChange (value: boolean) {
loading.value = true
setTimeout(() => {
activeValue.value = value
loading.value = false
}, 2000)
}
}
}
})
</script>
32 changes: 31 additions & 1 deletion src/switch/demos/zhCN/loading.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
# 加载中

</markdown>

<template>
<n-switch loading />
<n-space>
<n-switch loading />
<n-switch
:value="activeValue"
:loading="loading"
@update:value="handleChange"
/>
</n-space>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup () {
const activeValue = ref(false)
const loading = ref(false)
return {
activeValue,
loading,
handleChange (value: boolean) {
loading.value = true
setTimeout(() => {
activeValue.value = value
loading.value = false
}, 2000)
}
}
}
})
</script>
2 changes: 2 additions & 0 deletions src/switch/src/styles/index.cssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export default cB('switch', `
transition: color .3s var(--n-bezier);
`, [
iconSwitchTransition({
left: '50%',
top: '50%',
originalTransform: 'translateX(-50%) translateY(-50%)'
})
]),
Expand Down

0 comments on commit 3ed47db

Please sign in to comment.