Skip to content

Commit

Permalink
perf(select): group title not exist still renders children
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 committed Jan 3, 2025
1 parent d0c71e5 commit e3b2909
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/select/hooks/useSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
dynamicIndex++;
return res;
};
if ((option as SelectOptionGroup).group && (option as SelectOptionGroup).children) {
if ((option as SelectOptionGroup).children) {
return {
...option,
children: (option as SelectOptionGroup).children.map((child) => getFormatOption(child)),
Expand Down Expand Up @@ -84,7 +84,7 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
const res: TdOptionProps[] = [];
const getOptionsList = (options: TdOptionProps[]) => {
for (const option of options) {
if ((option as SelectOptionGroup).group) {
if ((option as SelectOptionGroup).children) {
getOptionsList((option as SelectOptionGroup).children);
} else {
res.push(option);
Expand Down Expand Up @@ -120,7 +120,7 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
const res: SelectOption[] = [];

options.value.forEach((option) => {
if ((option as SelectOptionGroup).group && (option as SelectOptionGroup).children) {
if ((option as SelectOptionGroup).children) {
res.push({
...option,
children: (option as SelectOptionGroup).children.filter(filterMethods),
Expand Down
1 change: 0 additions & 1 deletion src/select/option-group-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export default {
/** 分组别名 */
label: {
type: String,
default: '',
},
};
2 changes: 1 addition & 1 deletion src/select/optionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineComponent({

return () => (
<li class={classes.value}>
<div class={`${COMPONENT_NAME.value}__header`}>{props.label}</div>
{(props.label ?? false) && <div class={`${COMPONENT_NAME.value}__header`}>{props.label}</div>}
{renderTNodeJSX('default')}
</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 @@ -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.group) {
if (item.children) {
return (
<OptionGroup label={item.group} divider={item.divider}>
{renderOptionsContent(item.children)}
Expand Down

0 comments on commit e3b2909

Please sign in to comment.