Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Metronic 9 - datepicker not closing after selecting the date


I have copied the code from Metronic 9 for datepicker, particularly on this section

<Popover>
<PopoverTrigger asChild>
<button
id="date"
className={cn(
'input data-[state=open]:border-primary',
!date && 'text-muted-foreground'
)}
>
<KeenIcon icon="calendar" className="-ms-0.5" />
{date ? format(date, 'LLL dd, y') : <span>Pick a date</span>}
</button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
initialFocus
mode="single" // Single date selection
defaultMonth={date}
selected={date}
onSelect={setDate}
// numberOfMonths={2}
/>
</PopoverContent>
</Popover>


After selecting the date, the calendar remains open and does not close. The intended behaviour is for the calendar to close after a date has been selected. To close the calendar, the user would need to click outside the calendar again.

How can I configure it to achieve this effect?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi,

The popover component is quite flexible and you can apply your own logic to make it auto-closable after date range selection. To enable reset/apply buttons for the daterangepicker please change "/vite/src/pages/dashboards/demo1/light-sidebar/Demo1LightSidebarPage.tsx" and update with https://gist.github.com/keen333/a0dee16f81f6d52e2396dac31e4bf275


Regards,
Sean



That works, thanks a lot!



All the best happy


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(