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

fix: #1854 #1875 #1876

Merged
merged 3 commits into from
Aug 20, 2021
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
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