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

feat: add cascader keys disabled #2697

Merged
merged 7 commits into from
Aug 17, 2023
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
14 changes: 8 additions & 6 deletions src/cascader/cascader.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
name | type | default | description | required
-- | -- | -- | -- | --
autofocus | Boolean | - | \- | N
borderless | Boolean | false | \- | N
checkProps | Object | - | Typescript:`CheckboxProps`,[Checkbox API Documents](./checkbox?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
checkStrictly | Boolean | false | \- | N
clearable | Boolean | false | \- | N
Expand All @@ -15,7 +16,7 @@ empty | String / Slot / Function | - | Typescript:`string \| TNode`。[see mor
filter | Function | - | Typescript:`(filterWords: string, node: TreeNodeModel) => boolean \| Promise<boolean>` | N
filterable | Boolean | false | \- | N
inputProps | Object | - | Typescript:`InputProps`,[Input API Documents](./input?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
keys | Object | - | Typescript:`CascaderKeysType` `interface CascaderKeysType { value?: string; label?: string; children?: string \| boolean }`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
keys | Object | - | Typescript:`TreeKeysType`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
lazy | Boolean | true | \- | N
load | Function | - | Typescript:`(node: TreeNodeModel<CascaderOption>) => Promise<Array<CascaderOption>>` | N
Expand All @@ -29,23 +30,24 @@ options | Array | [] | Typescript:`Array<CascaderOption>` | N
placeholder | String | undefined | \- | N
popupProps | Object | - | Typescript:`PopupProps`,[Popup API Documents](./popup?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
popupVisible | Boolean | - | \- | N
defaultPopupVisible | Boolean | - | uncontrolled property | N
readonly | Boolean | false | \- | N
reserveKeyword | Boolean | false | \- | N
selectInputProps | Object | - | Typescript:`SelectInputProps`,[SelectInput API Documents](./select-input?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
showAllLevels | Boolean | true | \- | N
size | String | medium | optionslarge/medium/small。Typescript:`SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
status | String | default | optionsdefault/success/warning/error | N
size | String | medium | options: large/medium/small。Typescript:`SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
status | String | default | options: default/success/warning/error | N
suffix | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
suffixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
tagInputProps | Object | - | Typescript:`TagInputProps`,[TagInput API Documents](./tag-input?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
tagProps | Object | - | Typescript:`TagProps`,[Tag API Documents](./tag?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
tips | String / Slot / Function | - | tips at the bottom of cascader。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
trigger | String | click | optionsclick/hover | N
trigger | String | click | options: click/hover | N
value | String / Number / Array | [] | `v-model` is supported。Typescript:`CascaderValue<CascaderOption>` `type CascaderValue<T extends TreeOptionData = TreeOptionData> = string \| number \| T \| Array<CascaderValue<T>>`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
defaultValue | String / Number / Array | [] | uncontrolled property。Typescript:`CascaderValue<CascaderOption>` `type CascaderValue<T extends TreeOptionData = TreeOptionData> = string \| number \| T \| Array<CascaderValue<T>>`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
valueDisplay | String / Slot / Function | - | `MouseEvent<SVGElement>`。Typescript:`string \| TNode<{ value: CascaderValue<CascaderOption>; onClose: (index: number) => void; displayValue?: CascaderValue<CascaderOption> }>`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
valueMode | String | onlyLeaf | optionsonlyLeaf/parentFirst/all | N
valueType | String | single | optionssingle/full | N
valueMode | String | onlyLeaf | options: onlyLeaf/parentFirst/all | N
valueType | String | single | options: single/full | N
onBlur | Function | | Typescript:`(context: { value: CascaderValue<CascaderOption> } & SelectInputBlurContext ) => void`<br/> | N
onChange | Function | | Typescript:`(value: CascaderValue<CascaderOption>, context: CascaderChangeContext<CascaderOption>) => void`<br/>[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts)。<br/>`interface CascaderChangeContext<CascaderOption> { node?: TreeNodeModel<CascaderOption>; source: CascaderChangeSource }`<br/><br/>`import { TreeNodeModel } from '@Tree'`<br/><br/>`type CascaderChangeSource = 'invalid-value' \| 'check' \| 'clear' \| 'uncheck'`<br/> | N
onFocus | Function | | Typescript:`(context: { value: CascaderValue<CascaderOption>; e: FocusEvent }) => void`<br/> | N
Expand Down
3 changes: 2 additions & 1 deletion src/cascader/cascader.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
autofocus | Boolean | - | 自动聚焦 | N
borderless | Boolean | false | 无边框模式 | N
checkProps | Object | - | 参考 checkbox 组件 API。TS 类型:`CheckboxProps`,[Checkbox API Documents](./checkbox?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
checkStrictly | Boolean | false | 父子节点选中状态不再关联,可各自选中或取消 | N
clearable | Boolean | false | 是否支持清空选项 | N
Expand All @@ -15,7 +16,7 @@ empty | String / Slot / Function | - | 无匹配选项时的内容,默认全
filter | Function | - | 自定义过滤方法,用于对现有数据进行搜索过滤,判断是否过滤某一项数据。TS 类型:`(filterWords: string, node: TreeNodeModel) => boolean \| Promise<boolean>` | N
filterable | Boolean | false | 是否可搜索 | N
inputProps | Object | - | 透传 Input 输入框组件的全部属性。TS 类型:`InputProps`,[Input API Documents](./input?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
keys | Object | - | 用来定义 value / label / children 在 `options` 中对应的字段别名。TS 类型:`CascaderKeysType` `interface CascaderKeysType { value?: string; label?: string; children?: string \| boolean }`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/cascader/type.ts) | N
keys | Object | - | 用来定义 value / label / children / disabled 在 `options` 中对应的字段别名。TS 类型:`TreeKeysType`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | 左侧文本。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
lazy | Boolean | true | 延迟加载 children 为 true 的子节点,即使 expandAll 被设置为 true,也同样延迟加载 | N
load | Function | - | 加载子树数据的方法(仅当节点 children 为 true 时生效)。TS 类型:`(node: TreeNodeModel<CascaderOption>) => Promise<Array<CascaderOption>>` | N
Expand Down
4 changes: 2 additions & 2 deletions src/cascader/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import props from './props';

import { useCascaderContext } from './hooks';
import {
CascaderValue, CascaderKeysType, TdSelectInputProps, TdCascaderProps,
CascaderValue, TreeKeysType, TdSelectInputProps, TdCascaderProps,
} from './interface';
import { useConfig, usePrefixClass, useCommonClassName } from '../hooks/useConfig';
import { PopupVisibleChangeContext } from '../popup';
Expand Down Expand Up @@ -102,7 +102,7 @@ export default defineComponent({

const renderCollapsedItems = () => {
const cascaderValue = this.innerValue || [];
const keys = (this.keys as CascaderKeysType) || DEFAULT_KEYS;
const keys = (this.keys as TreeKeysType) || DEFAULT_KEYS;
const value = Array.isArray(cascaderValue) ? cascaderValue : [cascaderValue];
const cascaderOptions = value.map((item) => {
const tmpValue = typeof item === 'object' ? item[keys.value] : item;
Expand Down
2 changes: 2 additions & 0 deletions src/cascader/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import TreeStore from '../_common/js/tree/tree-store';
import TreeNode from '../_common/js/tree/tree-node';
import { TreeNodeModel, TreeNodeValue } from '../_common/js/tree/types';

export { TreeKeysType } from '../common';

export * from './type';
export interface CascaderContextType
extends Pick<
Expand Down
4 changes: 3 additions & 1 deletion src/cascader/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { PropType } from 'vue';
export default {
/** 自动聚焦 */
autofocus: Boolean,
/** 无边框模式 */
borderless: Boolean,
/** 参考 checkbox 组件 API */
checkProps: {
type: Object as PropType<TdCascaderProps['checkProps']>,
Expand Down Expand Up @@ -38,7 +40,7 @@ export default {
inputProps: {
type: Object as PropType<TdCascaderProps['inputProps']>,
},
/** 用来定义 value / label / children 在 `options` 中对应的字段别名 */
/** 用来定义 value / label / children / disabled 在 `options` 中对应的字段别名 */
keys: {
type: Object as PropType<TdCascaderProps['keys']>,
},
Expand Down
17 changes: 8 additions & 9 deletions src/cascader/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import { TagInputProps } from '../tag-input';
import { TagProps } from '../tag';
import { TreeNodeModel } from '../tree';
import { PopupVisibleChangeContext } from '../popup';
import { TNode, TreeOptionData, SizeEnum } from '../common';
import { TNode, TreeOptionData, SizeEnum, TreeKeysType } from '../common';

export interface TdCascaderProps<CascaderOption extends TreeOptionData = TreeOptionData> {
/**
* 自动聚焦
*/
autofocus?: boolean;
/**
* 无边框模式
* @default false
*/
borderless?: boolean;
/**
* 参考 checkbox 组件 API
*/
Expand Down Expand Up @@ -59,9 +64,9 @@ export interface TdCascaderProps<CascaderOption extends TreeOptionData = TreeOpt
*/
inputProps?: InputProps;
/**
* 用来定义 value / label / children 在 `options` 中对应的字段别名
* 用来定义 value / label / children / disabled 在 `options` 中对应的字段别名
*/
keys?: CascaderKeysType;
keys?: TreeKeysType;
/**
* 左侧文本
*/
Expand Down Expand Up @@ -226,12 +231,6 @@ export interface TdCascaderProps<CascaderOption extends TreeOptionData = TreeOpt
onRemove?: (context: RemoveContext<CascaderOption>) => void;
}

export interface CascaderKeysType {
value?: string;
label?: string;
children?: string | boolean;
}

export type CascaderValue<T extends TreeOptionData = TreeOptionData> = string | number | T | Array<CascaderValue<T>>;

export interface CascaderChangeContext<CascaderOption> {
Expand Down
5 changes: 5 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export type CSSSelector = string;
export interface KeysType {
value?: string;
label?: string;
disabled?: string;
}

export interface TreeKeysType extends KeysType {
children?: string;
}

export interface HTMLElementAttributes {
Expand Down
8 changes: 5 additions & 3 deletions src/select/hooks/useSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
import { VNode } from 'vue';
import get from 'lodash/get';
import {
TdSelectProps, SelectKeysType, TdOptionProps, SelectOptionGroup, SelectValue,
TdSelectProps, TdOptionProps, SelectOptionGroup, SelectValue,
} from '../type';
import { KeysType } from '../../common';

type UniOption = (TdOptionProps | SelectOptionGroup) & {
index?: number;
Expand All @@ -20,7 +21,7 @@ type UniOption = (TdOptionProps | SelectOptionGroup) & {
export default function useSelectOptions(
props: TdSelectProps,
instance: ComponentInternalInstance,
keys: Ref<SelectKeysType>,
keys: Ref<KeysType>,
) {
// 内部 options 记录
const options = ref<UniOption[]>([]);
Expand All @@ -34,12 +35,13 @@ export default function useSelectOptions(
// 解析 props 中 options 字段的配置,以此初始化 innerOptions
const innerOptions: UniOption[] = props.options?.map((option) => {
const getFormatOption = (option: TdOptionProps) => {
const { value, label } = keys.value;
const { value, label, disabled } = keys.value;
const res = {
...option,
index: dynamicIndex,
label: get(option, label),
value: get(option, value),
disabled: get(option, disabled),
};
dynamicIndex += 1;
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/select/option-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export default {
},
/** 选项值 */
value: {
type: [String, Number, Boolean] as PropType<TdOptionProps['value']>,
type: [String, Number] as PropType<TdOptionProps['value']>,
},
};
2 changes: 1 addition & 1 deletion src/select/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
defaultInputValue: {
type: [String, Number] as PropType<TdSelectProps['defaultInputValue']>,
},
/** 用来定义 value / label 在 `options` 中对应的字段别名 */
/** 用来定义 value / label / disabled 在 `options` 中对应的字段别名 */
keys: {
type: Object as PropType<TdSelectProps['keys']>,
},
Expand Down
Loading
Loading