Skip to content

Commit

Permalink
fix(comp:select): loading get the first execution
Browse files Browse the repository at this point in the history
  • Loading branch information
kovsu committed Feb 9, 2023
1 parent 8849999 commit 1afd8b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 5 additions & 7 deletions packages/components/select/demo/Loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { ref } from 'vue'
import { SelectData } from '@idux/components/select'
const dataSource = ref<SelectData[]>([])
const dataSource = ref<SelectData[]>([{ label: 'Tom', value: 'tom' }])
const value = ref('')
const value = ref('tom')
const isLoading = ref(false)
const timer = ref<number | null>(null)
Expand All @@ -24,17 +24,15 @@ const onLoad = () => {
}
timer.value = setTimeout(() => {
isLoading.value = false
dataSource.value.push({ label: 'Tom', value: 'tom' })
dataSource.value.push({ label: 'Jack', value: 'jack' })
dataSource.value.push({ label: 'Alan', value: 'alan' })
}, 5000)
}, 3000)
}
function clear() {
isLoading.value = true
value.value = ''
if (dataSource.value.length > 0) {
dataSource.value.length = 0
if (dataSource.value.length > 1) {
dataSource.value.length = 1
}
}
</script>
18 changes: 8 additions & 10 deletions packages/components/select/src/panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ export default defineComponent({
const children = [<ListBox />]
const loading = props.loading

if (options.length > 0) {
if (loading) {
children.push(
<div class={`${common.prefixCls}-select-loading`}>
<IxSpin spinning={loading}></IxSpin>
</div>,
)
} else if (options.length > 0) {
const itemRender: VirtualItemRenderFn<FlattenedOption> = ({ item, index }) => {
const { type, ...rest } = item
return type === 'group' ? <OptionGroup index={index} {...rest} /> : <Option index={index} {...rest} />
Expand All @@ -106,15 +112,7 @@ export default defineComponent({
/>,
)
} else {
if (loading) {
children.push(
<div class={`${common.prefixCls}-select-loading`}>
<IxSpin spinning={loading}></IxSpin>
</div>,
)
} else {
children.push(<ɵEmpty v-slots={slots} empty={props.empty} />)
}
children.push(<ɵEmpty v-slots={slots} empty={props.empty} />)
}

return <div onMousedown={handlePanelMouseDown}>{children}</div>
Expand Down

0 comments on commit 1afd8b1

Please sign in to comment.