Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix select issue after refactoring #991

Merged
merged 7 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/select/demos/noborder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<t-select
v-model="value"
:bordered="false"
style="width: 200px;"
style="width: 200px"
placeholder="-请选择-"
clearable
auto-width
:options="options"
/>
</div>
Expand Down
13 changes: 2 additions & 11 deletions examples/select/demos/prefix.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<template>
<div>
<t-select
v-model="value"
style="width: 200px;"
:options="options"
clearable
placeholder="-请选择-"
>
<icon
name="browse"
slot="prefixIcon"
/>
<t-select v-model="value" style="width: 200px" :options="options" clearable placeholder="-请选择-">
<icon name="browse" slot="prefixIcon" style="margin-right: 8px" />
</t-select>
</div>
</template>
Expand Down
11 changes: 9 additions & 2 deletions examples/select/demos/virtual-scroll.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<template>
<div class="tdesign-demo-select-base">
<t-select v-model="value" :options="options" placeholder="请选择" :scroll="{ type: 'virtual' }" />
<!-- 开启虚拟滚动请为select的panel设定好height 通过popupProps进行透传 -->
<t-select
v-model="value"
:options="options"
placeholder="请选择"
:scroll="{ type: 'virtual' }"
:popup-props="{ overlayStyle: { height: '300px' } }"
/>
</div>
</template>

Expand All @@ -9,7 +16,7 @@ export default {
data() {
const options = [];
for (let i = 0; i < 1000; i++) {
options.push({ label: `选项${i}`, value: String(i) });
options.push({ label: `选项${i + 1}`, value: String(i) });
}
return {
value: '',
Expand Down
2 changes: 2 additions & 0 deletions src/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export default mixins(getConfigReceiverMixins<Vue, PaginationConfig>('pagination
disabled={this.disabled}
class={this.sizerClass}
onChange={this.onSelectorChange}
autoWidth={true}
>
{this.sizeOptions.map((item, index) => (
<t-option value={item.value} label={item.label} key={index} />
Expand Down Expand Up @@ -382,6 +383,7 @@ export default mixins(getConfigReceiverMixins<Vue, PaginationConfig>('pagination
class={this.simpleClass}
onChange={this.toPage}
options={this.pageCountOption}
autoWidth={true}
/>
) : null}
{/* 向后按钮 */}
Expand Down
20 changes: 5 additions & 15 deletions src/select/optionGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
computed, defineComponent, ref, toRefs, watch, onMounted, inject,
computed, defineComponent, ref, toRefs, inject,
} from '@vue/composition-api';
import Vue from 'vue';
import { ScopedSlotReturnValue } from 'vue/types/vnode';
Expand All @@ -25,7 +25,6 @@ export default defineComponent({
setup(props: TdOptionGroupProps) {
const { divider } = toRefs(props);
const ulRef = ref<HTMLElement>(null);
const visible = ref(true);
const tSelect: any = inject('tSelect');
const classes = computed<ClassName>(() => [
name,
Expand All @@ -34,18 +33,7 @@ export default defineComponent({
[`${name}__divider`]: divider,
},
]);
const childrenChange = () => {
visible.value = [...(ulRef.value?.children || [])]?.some((liItem) => (liItem as any).__vue__.show === true);
};
onMounted(() => {
// 首次载入的时候也更新一次
childrenChange();
});
watch(tSelect.displayOptions, () => {
childrenChange();
});
return {
visible,
classes,
ulRef,
};
Expand All @@ -54,9 +42,11 @@ export default defineComponent({
const renderTNode = useTNodeJSX();
const children: ScopedSlotReturnValue = renderTNode('default');
return (
<li v-show={this.visible} class={this.classes}>
<li class={this.classes}>
<div class={`${name}__header`}>{this.label}</div>
<ul ref="ulRef">{children}</ul>
<ul class={`${prefix}-select__list`} ref="ulRef">
{children}
</ul>
</li>
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/select/select-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default defineComponent({
optionsContent = (visibleData || options).map((groupList: SelectOptionGroup) => {
const children = groupList.children.filter((item) => tSelect.displayOptionsMap.value.get(item));
return (
<t-option-group v-show={children.length} label={groupList.group} divider={groupList.divider}>
<t-option-group label={groupList.group} divider={groupList.divider}>
{this.renderSingleOption(children)}
</t-option-group>
);
Expand Down
3 changes: 2 additions & 1 deletion src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ export default defineComponent({
const initOptions = () => {
if (realOptions.value.length || isInit.value) return;

const children = renderTNode('default');
// 这里直接使用 context.slots 没办法拿到后续渲染赋进来的 default slots,采用如下方法动态获取
const children = getCurrentInstance().vnode.componentInstance.$scopedSlots.default?.({});
if (children) {
realOptions.value = parseOptions(children);
isInit.value = true;
Expand Down
Loading