最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Changing the default UI of Antd DatePicker component - Stack Overflow

programmeradmin0浏览0评论

I want to have a custom icon (not just the suffix icon - to replace the whole UI of the DatePicker), and when I click that icon, I want the DatePicker to open for me to select the date.

const [open, setOpen] = useState(false)
const handleIconClick = () => {
    setOpen(true)
};
    return(
<CalendarOutlined className="calendar-icon" onClick={handleIconClick} />
                    <DatePicker style={{display:'none'}}open={open} onOpenChange={setOpen} />
)

This is what I have tried. The DatePicker component is not displayed as display is set to none and when I click on the icon, the DatePicker open UI will render for quick second and disappear. I suspect this is also because the display is set to none.

Is there anyway I can achieve what I want while using the antd DatePicker or will I have to use the date input html element for this purpose?

I want to have a custom icon (not just the suffix icon - to replace the whole UI of the DatePicker), and when I click that icon, I want the DatePicker to open for me to select the date.

const [open, setOpen] = useState(false)
const handleIconClick = () => {
    setOpen(true)
};
    return(
<CalendarOutlined className="calendar-icon" onClick={handleIconClick} />
                    <DatePicker style={{display:'none'}}open={open} onOpenChange={setOpen} />
)

This is what I have tried. The DatePicker component is not displayed as display is set to none and when I click on the icon, the DatePicker open UI will render for quick second and disappear. I suspect this is also because the display is set to none.

Is there anyway I can achieve what I want while using the antd DatePicker or will I have to use the date input html element for this purpose?

Share Improve this question asked Jan 30 at 9:50 Upeka FernandoUpeka Fernando 1051 gold badge1 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can set its visibility to hidden from the style prop or through a className.

<DatePicker 
  // className="some-classname-which-sets-visibility-to-hidden" or
  style={{visibility:'hidden'}}
  open={open} 
  onOpenChange={setOpen} 
/>

Example: https://codepen.io/Gabriele-Petrioli/pen/myboyyX?editors=0010


Also found a discussion with an example in github: allow opening DatePicker without need for input box

发布评论

评论列表(0)

  1. 暂无评论