background
The form cascading menu needs to add a header to express the meaning of each level.
If your antd
version is greater than or equal to it 4.4.0
, you can directly use dropdownRender
attribute customization, and you can skip this article directly.
parameter
illustrate
type
default value
Version
dropdownRender
Customize drop-down box content
(menus: ReactNode) => ReactNode
-
4.4.0
Since the blogger's antd version is too low and cannot use dropdownRender
attributes, he has to find another way.
accomplish
import {
Cascader} from 'antd' ;
import React, {
useState } from 'react' ;
import './index.css' ;
export default function ( ) {
const [ popupVisible, setPopupVisible] = useState ( false ) ;
return (
< div>
< div className= "navSpacePopup-container" style= {
{
display : popupVisible ? 'block' : 'none' } } >
< div className= "header" >
< span> 部门< / span>
< span> 产品< / span>
< span> 业务< / span>
< / div>
< div className= "body" / >
< div className= "footer" / >
< / div>
< Cascader
options= {
options}
popupClassName= {
'navSpacePopup' }
showSearch= {
true }
onSearch= {
( search ) => {
const uls : any = document. querySelector ( '.navSpacePopup .ant-cascader-menus .ant-cascader-menu' ) ;
if ( search) {
uls. style. width = '100%' ;
} else {
uls. style. width = '33%' ;
}
} }
getPopupContainer= {
( ) => document. querySelector ( '.navSpacePopup-container .body' ) }
onPopupVisibleChange= {
( val ) => setPopupVisible ( val) }
/ >
< / div>
)
}
.navSpacePopup-container {
position : absolute;
top : 224px;
right : 25px;
width : 65%;
height : 210px;
z-index : 999;
background : #fff;
border : 1px solid #ddd;
}
.navSpacePopup-container .header {
width : 100%;
height : 32px;
line-height : 32px;
display : grid;
grid-template-columns : auto auto auto;
text-align : center;
}
.navSpacePopup-container .footer {
width : 100%;
height : 32px;
line-height : 32px;
}
.navSpacePopup-container .body {
width : 100%;
height : 248px;
}
.navSpacePopup-container .body > div {
position : relative !important ;
}
.navSpacePopup {
width : 100%;
position : relative !important ;
top : 0 !important ;
left : 0 !important ;
box-shadow : none;
}
.navSpacePopup .ant-cascader-menus .ant-cascader-menu {
width : 33%;
}
.navSpacePopup .ant-cascader-menus .ant-cascader-menu .ant-cascader-menu-item .ant-cascader-menu-item-content {
flex : none !important ;
}
.navSpacePopup .ant-cascader-menus .ant-cascader-menu .ant-cascader-menu-item {
display : flex;
justify-content : space-between;
}
.navSpacePopup .ant-cascader-menus .ant-cascader-menu {
flex-grow : inherit;
}