Skip to content

Commit

Permalink
Merge pull request #1876 from XiaoMi/hotfix/#1875
Browse files Browse the repository at this point in the history
  • Loading branch information
solarjoker committed Aug 20, 2021
2 parents 81c2935 + 4f861af commit 3bda485
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion components/cascader/Cascader.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const Cascader = (props) => {
const [filterOptions, setFilterOptions] = useState(false)
// 缓存原始value,用户可能点击option但是没选中,用于恢复初始value
const [cacheValue, setCacheValue] = useState(value || defaultValue || [])
// 选中态 value
const [cascaderValue, setCascaderValue] = useState(value || defaultValue || [])
const [cascaderLabel, setCascaderLabel] = useState(
getCascaderLabel(value || defaultValue || [], fieldNames, displayRender, data)
Expand All @@ -80,7 +81,7 @@ const Cascader = (props) => {
useEffect(() => {
setFocusOptionIndex(-1)
currentDeep.current = 0
if (onOpen) {
if (onOpen && popperShow) {
const dataSource = onOpen()
if (dataSource && dataSource.toString() === '[object Promise]') {
dataSource.then((res) => {
Expand Down
8 changes: 6 additions & 2 deletions docs/demo/cascader/section-advanced.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,22 @@ class Demo extends React.Component {
constructor () {
super()
this.state = {
options: []
options: [],
value: ['手机','手机2']
}
}
render(){
return(
<Cascader
onChange={(value)=>{
console.log('on change', value)
this.setState({
value: value
})
}}
data={this.state.options}
style={{ width: 240 }}
defaultValue={['电视','小米电视4C']}
value={this.state.value}
onOpen={()=>{
const {options} = this.state
if(options.length === 0){
Expand Down
1 change: 1 addition & 0 deletions docs/zh-CN/components/cascader.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import DemoAdvanced from '../../demo/cascader/section-advanced.jsx'
| 名称 | 说明 | 类型 | 参数 | 返回值 |
| -------- | ------------ | -------------------------- | ------------------ | ------ |
| onChange | 选择后的回调 | (values: string[]) => void | values: 选中项集合 | - |
| onActiveItemChange | 选中项改变时的回调 | (values: string[]) => void | values: 选中项集合 | - |
| onOpen | 下拉菜单打开时回调 | () => void | - | - |
| onClose | 下拉菜单关闭时回调 | () => void | - | - |

Expand Down

0 comments on commit 3bda485

Please sign in to comment.