我想自定义 antd Select
。当用户点击Select
antd 时,它Option
应该显示在 antd 之上,Select
而不是显示在Select
antd Select
:https : //ant.design/components/select/
预期行为:1
实际行为:2
JSX
import { FaPlane, FaWater } from "react-icons/fa";
//outside of class
const shipmentType = {
sea: [
{ name: "FCL", desc: "FULL CONTAINER LOAD" },
{ name: "LCL", desc: "LESS CONTAINER LOAD" }
],
air: [{ name: "AIR", desc: "AIR DELIVERY" }]
};
//inside of class
render(){
return(
<Select
className="container-dropdown"
onChange={this.onSelectChange}
defaultValue={
<DisplayContainer data={shipmentType.sea[0]} />
}
key={ shipmentType.sea[0]}
>
<Option value={shipmentType.sea[0].name}>
<DisplayContainer data={shipmentType.sea[0]} />
</Option>
<Option value={shipmentType.sea[1].name}>
<DisplayContainer data={shipmentType.sea[1]} />
</Option>
</Select>
);
}
DisplayContainer.js 组件
const DisplayContainer = ({ data }) => {
return (
<div
style={{
width: "120px",
height: "45px",
display: "flex",
flexFlow: "column",
justifyContent: "center",
alignItems: "center"
}}
>
<span
style={{
display: "block",
fontSize: "8px",
padding: "5px 0px 0px 10px"
}}
>
{data.desc}
</span>
<span style={{ padding: "2px 0px 0px 14px" }}>
{data.name === "AIR" ? <FaPlane /> : <FaWater />}
<span
style={{ display: "inline", marginLeft: "14px", fontSize: "16px" }}
>
{data.name}
</span>
</span>
</div>
);
};
应用程序.css
.container-dropdown {
height: 53px;
width: 140px;
border: 0px solid white;
border-radius: 0px;
cursor: pointer;
font-size: 18px;
margin: 0px;
padding: 0px;
}
自定义antd.css
.ant-select-selection.ant-select-selection--single {
border-radius: 0px 8px 8px 0px;
height: 53px;
}
.ant-select-selection-selected-value {
height: 53px;
padding: 0px;
margin: 0px;
}
.ant-select-selection__rendered {
padding: 0px;
margin: 0px;
}
.ant-select-dropdown-menu.ant-select-dropdown-menu-root.ant-select-dropdown-menu-vertical {
padding: 0px;
margin: 0px;
}
.ant-select-dropdown-menu-item {
padding: 0px;
margin: 0px;
}
我怎样才能做到这一点?我已经花了几个小时的时间。但我没能成功。我会很感激你的。谢谢
编辑01:
当用户单击该Select
框时
我希望顶部Option
(即FCL
)上升并Select
像这样盖住盒子:
我不希望Options
(ieFCL
和LCL
) 都显示在Select
框下方: