Skip to content

Commit

Permalink
fix: group select filter (#1026)
Browse files Browse the repository at this point in the history
* fix: group select  filter

* fix: radio nil check

* test: snap update

* test: snap update
  • Loading branch information
PengYYYYY committed Jun 22, 2022
1 parent 72206c0 commit a7cff91
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 324 deletions.
3 changes: 2 additions & 1 deletion src/radio/group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { VNode, defineComponent, h, provide, reactive, ref, computed, onMounted, watch, nextTick, toRefs } from 'vue';
import isString from 'lodash/isString';
import isNumber from 'lodash/isNumber';
import isNil from 'lodash/isNil';
import props from './radio-group-props';
import { RadioOptionObj, RadioOption } from './type';
import Radio from './radio';
Expand Down Expand Up @@ -76,7 +77,7 @@ export default defineComponent({
const radioGroupName = usePrefixClass('radio-group');
const renderSlot = useTNodeDefault();
const renderBlock = (): VNode => {
if (props.variant.includes('filled') && innerValue.value)
if (props.variant.includes('filled') && isNil(innerValue.value))
return <div style={barStyle.value} class={`${radioGroupName.value}__bg-block`} />;
};
const renderOptions = (): VNode[] => {
Expand Down
1 change: 0 additions & 1 deletion src/select/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TdSelectProps, TdOptionProps, SelectValue, SelectOption, SelectOptionGr

export const selectInjectKey: InjectionKey<
ComputedRef<{
slots: Slots;
hoverIndex: number;
selectValue: TdSelectProps['value'];
size: TdSelectProps['size'];
Expand Down
9 changes: 6 additions & 3 deletions src/select/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { computed, Slots, VNode, Ref } from 'vue';
import isArray from 'lodash/isArray';
import get from 'lodash/get';
import cloneDeep from 'lodash/cloneDeep';

import { useChildComponentSlots } from '../hooks/slot';
import { TdSelectProps, TdOptionProps, SelectOptionGroup, SelectKeysType, SelectValue } from './type';

type UniOption = (TdOptionProps | SelectOptionGroup) & {
index?: number;
slots?: Slots;
};

export const useSelectOptions = (props: TdSelectProps, keys: Ref<SelectKeysType>) => {
const getChildComponentSlots = useChildComponentSlots();

const options = computed(() => {
let innerOptions = cloneDeep(props.options);
let dynamicIndex = 0;

// 统一处理 keys,处理通用数据
innerOptions = innerOptions.map((option) => {
const innerOptions: UniOption[] = props.options.map((option) => {
const getFormatOption = (option: TdOptionProps) => {
const { value, label } = keys.value;
const res = {
Expand Down
15 changes: 14 additions & 1 deletion src/select/select-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ export default defineComponent({
return option.label?.indexOf(`${props.inputValue}`) > -1;
};

return props.options.filter(filterMethods);
const res: SelectOption[] = [];
props.options.forEach((option) => {
if ((option as SelectOptionGroup).group && (option as SelectOptionGroup).children) {
res.push({
...option,
children: (option as SelectOptionGroup).children.filter(filterMethods),
});
}
if (filterMethods(option)) {
res.push(option);
}
});

return res;
});

const isEmpty = computed(() => !displayOptions.value.length);
Expand Down
3 changes: 1 addition & 2 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default defineComponent({

const placeholderText = computed(
() =>
((!props.multiple && innerPopupVisible.value && getSingleContent(innerValue.value, props.options)) ||
((!props.multiple && innerPopupVisible.value && getSingleContent(innerValue.value, optionsList.value)) ||
props.placeholder) ??
t(global.value.placeholder),
);
Expand Down Expand Up @@ -186,7 +186,6 @@ export default defineComponent({
};

const SelectProvide = computed(() => ({
slots,
max: props.max,
multiple: props.multiple,
hoverIndex: hoverIndex.value,
Expand Down
Loading

0 comments on commit a7cff91

Please sign in to comment.