Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(Cascader): add placeholder attr #2597

Merged
merged 1 commit into from
Feb 27, 2024
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
9 changes: 5 additions & 4 deletions src/cascader/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

name | type | default | description | required
-- | -- | -- | -- | --
close-btn | Boolean / Slot | true | \- | N
keys | Object | - | Typescript:`KeysType` | N
close-btn | Boolean / Slot | true | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
keys | Object | - | Typescript:`KeysType`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
options | Array | [] | Typescript:`Array<CascaderOption>` | N
placeholder | String | 选择选项 | \- | N
sub-titles | Array | [] | Typescript:`Array<string>` | N
theme | String | step | optionsstep/tab | N
title | String / Slot | - | \- | N
theme | String | step | options: step/tab | N
title | String / Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
value | String / Number | null | \- | N
default-value | String / Number | undefined | uncontrolled property | N
visible | Boolean | false | \- | N
Expand Down
7 changes: 4 additions & 3 deletions src/cascader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ isComponent: true

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
close-btn | Boolean / Slot | true | 关闭按钮 | N
keys | Object | - | 用来定义 value / label 在 `options` 中对应的字段别名。TS 类型:`KeysType` | N
close-btn | Boolean / Slot | true | 关闭按钮。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
keys | Object | - | 用来定义 value / label 在 `options` 中对应的字段别名。TS 类型:`KeysType`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
options | Array | [] | 可选项数据源。TS 类型:`Array<CascaderOption>` | N
placeholder | String | 选择选项 | 未选中时的提示文案 | N
sub-titles | Array | [] | 每级展示的次标题。TS 类型:`Array<string>` | N
theme | String | step | 展示风格。可选项:step/tab | N
title | String / Slot | - | 标题 | N
title | String / Slot | - | 标题。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
value | String / Number | null | 选项值 | N
default-value | String / Number | undefined | 选项值。非受控属性 | N
visible | Boolean | false | 是否展示 | N
Expand Down
1 change: 1 addition & 0 deletions src/cascader/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ exports[`Cascader Cascader keys demo works fine 1`] = `
},
]
}}"
placeholder="未选中时的提示文案"
title="请选择地址"
visible="{{false}}"
bind:change="onChange"
Expand Down
1 change: 1 addition & 0 deletions src/cascader/_example/keys/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
keys="{{keys}}"
options="{{options}}"
title="请选择地址"
placeholder="未选中时的提示文案"
bind:change="onChange"
></t-cascader>
8 changes: 3 additions & 5 deletions src/cascader/cascader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface CascaderProps extends TdCascaderProps {}

type OptionsType = TdCascaderProps['options']['value'];

const defaultOptionLabel = '选择选项';
@wxComponent()
export default class Cascader extends SuperComponent {
externalClasses = [`${prefix}-class`];
Expand All @@ -35,9 +34,8 @@ export default class Cascader extends SuperComponent {
stepIndex: 0,
selectedIndexes: [],
selectedValue: [],
defaultOptionLabel,
scrollTopList: [],
steps: [defaultOptionLabel],
steps: [],
};

observers = {
Expand All @@ -56,7 +54,7 @@ export default class Cascader extends SuperComponent {
},

'selectedIndexes, options'() {
const { options, selectedIndexes, keys } = this.data;
const { options, selectedIndexes, keys, placeholder } = this.data;
const selectedValue = [];
const steps = [];
const items = [options];
Expand All @@ -76,7 +74,7 @@ export default class Cascader extends SuperComponent {
}

if (steps.length < items.length) {
steps.push(defaultOptionLabel);
steps.push(placeholder);
}

this.setData({
Expand Down
2 changes: 1 addition & 1 deletion src/cascader/cascader.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<view wx:if="{{theme == 'step'}}" class="{{name}}__steps">
<view wx:for="{{steps}}" wx:key="index" class="{{name}}__step" bind:tap="onStepClick" data-index="{{index}}">
<view
class="{{name}}__step-dot {{name}}__step-dot--{{item !== defaultOptionLabel ? 'active' : ''}} {{name}}__step-dot--{{index === steps.length - 1 ? 'last' : ''}}"
class="{{name}}__step-dot {{name}}__step-dot--{{item !== placeholder ? 'active' : ''}} {{name}}__step-dot--{{index === steps.length - 1 ? 'last' : ''}}"
></view>
<view class="{{name}}__step-label {{name}}__step-label--{{index === stepIndex ? 'active' : ''}}">
{{ item }}
Expand Down
5 changes: 5 additions & 0 deletions src/cascader/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const props: TdCascaderProps = {
type: Array,
value: [],
},
/** 未选中时的提示文案 */
placeholder: {
type: String,
value: '选择选项',
},
/** 每级展示的次标题 */
subTitles: {
type: Array,
Expand Down
8 changes: 8 additions & 0 deletions src/cascader/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export interface TdCascaderProps<CascaderOption extends TreeOptionData = TreeOpt
type: ArrayConstructor;
value?: Array<CascaderOption>;
};
/**
* 未选中时的提示文案
* @default 选择选项
*/
placeholder?: {
type: StringConstructor;
value?: string;
};
/**
* 每级展示的次标题
* @default []
Expand Down
Loading