Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/components/select/components/select-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default defineComponent({
return (
<ul class={`${COMPONENT_NAME.value}__list`}>
{options.map((item: SelectOptionGroup & TdOptionProps & { slots: Slots } & { $index: number }, index) => {
if (item.children) {
if (item.children?.length > 0 || !!item.group) {
return (
<OptionGroup label={item.group} divider={item.divider}>
{renderOptionsContent(item.children)}
Expand All @@ -73,7 +73,7 @@ export default defineComponent({
}
return (
<Option
{...omit(item, 'index', '$index', 'className', 'tagName')}
{...omit(item, 'index', '$index', 'className', 'tagName', 'children')}
{...(isVirtual.value
? {
rowIndex: item.$index,
Expand Down
11 changes: 6 additions & 5 deletions packages/components/select/hooks/useSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useSelectOptions = (
let dynamicIndex = 0;
// 统一处理 keys,处理通用数据
const innerOptions: UniOption[] =
props.options?.map((option) => {
props.options?.map((option: SelectOptionGroup) => {
const getFormatOption = (option: TdOptionProps) => {
const { value, label, disabled } = keys.value;
const restOption = omit(option, [value, label, disabled]) as Partial<TdOptionProps>;
Expand All @@ -37,10 +37,10 @@ export const useSelectOptions = (
dynamicIndex++;
return res;
};
if ((option as SelectOptionGroup).children) {
if (option.children?.length > 0 || !!option.group) {
return {
...option,
children: (option as SelectOptionGroup).children.map((child) => getFormatOption(child)),
children: option.children.map((child) => getFormatOption(child)),
};
}
return getFormatOption(option);
Expand Down Expand Up @@ -88,8 +88,9 @@ export const useSelectOptions = (
const res: TdOptionProps[] = [];
const getOptionsList = (options: TdOptionProps[]) => {
for (const option of options) {
if ((option as SelectOptionGroup).children) {
getOptionsList((option as SelectOptionGroup).children);
const item = option as SelectOptionGroup;
if (item.children?.length > 0 || !!item.group) {
getOptionsList(item.children);
} else {
res.push(option);
}
Expand Down