From 2b2cc4add292875d268ec2f1ba4b2deaf20764e8 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 24 Jul 2021 19:36:10 +0800 Subject: [PATCH] feat(Cascader): add option slot (#9111) --- src/cascader/README.md | 9 +++++---- src/cascader/README.zh-CN.md | 7 ++++--- src/cascader/index.js | 6 +++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cascader/README.md b/src/cascader/README.md index cc9330993..754a6a7c7 100644 --- a/src/cascader/README.md +++ b/src/cascader/README.md @@ -192,13 +192,14 @@ export default { | --- | --- | --- | | change | Emitted when active option changed | `{ value, selectedOptions, tabIndex }` | | finish | Emitted when all options is selected | `{ value, selectedOptions, tabIndex }` | -| close | Emmitted when the close icon is clicked | - | +| close | Emitted when the close icon is clicked | - | ### Slots -| Name | Description | -| ----- | ------------ | -| title | Custom title | +| Name | Description | SlotProps | +| --- | --- | --- | +| title | Custom title | - | +| option `v2.12.25` | Custom option text | _{ option: Option, selected: boolean }_ | ### Less Variables diff --git a/src/cascader/README.zh-CN.md b/src/cascader/README.zh-CN.md index 7e4d8fbfc..31733f24a 100644 --- a/src/cascader/README.zh-CN.md +++ b/src/cascader/README.zh-CN.md @@ -210,9 +210,10 @@ export default { ### Slots -| 名称 | 说明 | -| ----- | -------------- | -| title | 自定义顶部标题 | +| 名称 | 说明 | 参数 | +| ----------------- | -------------- | --------------------------------------- | +| title | 自定义顶部标题 | - | +| option `v2.12.25` | 自定义选项文字 | _{ option: Option, selected: boolean }_ | ### 样式变量 diff --git a/src/cascader/index.js b/src/cascader/index.js index c288d44c5..7d497660d 100644 --- a/src/cascader/index.js +++ b/src/cascader/index.js @@ -200,6 +200,10 @@ export default createComponent({ selectedOption && option[this.valueKey] === selectedOption[this.valueKey]; + const Text = this.slots('option', { option, selected: isSelected }) || ( + {option[this.textKey]} + ); + return (
  • - {option[this.textKey]} + {Text} {isSelected ? ( ) : null}