Skip to content

Commit

Permalink
Fix #5970: Calendar hideOnRangeSelection (#5971)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Feb 15, 2024
1 parent 67117a2 commit 25cdec3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/doc/calendar/rangedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function RangeDoc(props) {

const code = {
basic: `
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput />
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput hideOnRangeSelection />
`,
javascript: `
import React, { useState } from "react";
Expand All @@ -19,7 +19,7 @@ export default function RangeDemo() {
return (
<div className="card flex justify-content-center">
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput />
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput hideOnRangeSelection />
</div>
)
}
Expand All @@ -34,7 +34,7 @@ export default function RangeDemo() {
return (
<div className="card flex justify-content-center">
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput />
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput hideOnRangeSelection />
</div>
)
Expand All @@ -50,7 +50,7 @@ export default function RangeDemo() {
</p>
</DocSectionText>
<div className="card flex justify-content-center">
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput />
<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="range" readOnlyInput hideOnRangeSelection />
</div>
<DocSectionCode code={code} />
</>
Expand Down
6 changes: 6 additions & 0 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,12 @@ export const Calendar = React.memo(

selectedValues = [startDate, endDate];
updateModel(event, selectedValues);

if (props.hideOnRangeSelection && endDate !== null) {
setTimeout(() => {
setOverlayVisibleState(false);
}, 150);
}
} else {
selectedValues = [date, null];
updateModel(event, selectedValues);
Expand Down
1 change: 1 addition & 0 deletions components/lib/calendar/CalendarBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export const CalendarBase = ComponentBase.extend({
formatDateTime: null,
headerTemplate: null,
hideOnDateTimeSelect: false,
hideOnRangeSelection: false,
hourFormat: '24',
icon: null,
iconPos: 'right',
Expand Down
4 changes: 4 additions & 0 deletions components/lib/calendar/calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ interface CalendarBaseProps {
* @defaultValue false
*/
hideOnDateTimeSelect?: boolean | undefined;
/**
* Whether to hide the overlay on date selection is completed when selectionMode is range.
*/
hideOnRangeSelection?: boolean | undefined;
/**
* Specifies 12 or 24 hour format.
* @defaultValue 24
Expand Down

0 comments on commit 25cdec3

Please sign in to comment.