Skip to content

Commit 1d107b6

Browse files
committed
DateTimePicker-cleardate
1 parent 328a7b1 commit 1d107b6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

docs/documentation/docs/controls/DateTimePicker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ The `DateTimePicker` control can be configured with the following properties:
7373
| maxDate | Date | no | The maximum allowable date. |
7474
| minDate | Date | no | The minimum allowable date. |
7575
| minutesIncrementStep | MinutesIncrement | no | Specifies minutes' increment step for `TimeDisplayControlType.Dropdow` |
76+
| showClearDate | boolean | no | Controls whether the clearDate iconbutton must be available when date is selected, default to false
77+
| showClearDateIcon | string | no | Controls the icon used for clearDate iconbutton. Defaults to 'RemoveEvent'
7678

7779
Enum `TimeDisplayControlType`
7880

src/controls/dateTimePicker/DateTimePicker.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isEqual } from '@microsoft/sp-lodash-subset';
33
import { TimeConvention, DateConvention } from "./DateTimeConventions";
44
import { DatePicker } from "office-ui-fabric-react/lib/DatePicker";
55
import { Label } from "office-ui-fabric-react/lib/Label";
6+
import { IconButton } from "office-ui-fabric-react/lib/Button";
67
import ErrorMessage from "../errorMessage/ErrorMessage";
78
import styles from "./DateTimePicker.module.scss";
89
import HoursComponent from "./HoursComponent";
@@ -97,9 +98,11 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
9798
* Function called when the DatePicker Office UI Fabric component selected date changed
9899
*/
99100
private onSelectDate = (date: Date): void => {
101+
100102
if (!TimeHelper.isValidDate(date)) {
101103
return;
102104
}
105+
103106
// Get hours, minutes and seconds from state or default to zero
104107
const { hours = 0, minutes = 0, seconds = 0 } = this.state;
105108
const day = TimeHelper.cloneDate(date);
@@ -109,7 +112,14 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
109112
this.setState({ day }, () => this.delayedValidate(this.state.day));
110113
}
111114

112-
115+
/**
116+
* Function called from the clearDate iconbutton
117+
*/
118+
private clearDate() {
119+
this.setState({
120+
day: null
121+
});
122+
}
113123

114124
/**
115125
* Function called when hours value have been changed
@@ -225,7 +235,9 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
225235
showLabels,
226236
minDate,
227237
maxDate,
228-
minutesIncrementStep
238+
minutesIncrementStep,
239+
showClearDate = false,
240+
showClearDateIcon= 'RemoveEvent'
229241
} = this.props;
230242

231243
const { textErrorMessage } = dateStrings;
@@ -322,6 +334,8 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
322334
}}
323335
/>
324336
</div>
337+
{showClearDate === true && this.state.day !==null ? <IconButton iconProps={{iconName: showClearDateIcon}} onClick={() => this.clearDate()} /> : <></>}
338+
325339
</div>
326340

327341
{timeElm}

src/controls/dateTimePicker/IDateTimePickerProps.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,14 @@ export interface IDateTimePickerProps {
131131
* Specifies minutes' increment step
132132
*/
133133
minutesIncrementStep?: MinutesIncrement;
134+
135+
/**
136+
* Whether the clearDate iconbutton must be available when date is selected, default to false
137+
*/
138+
showClearDate?: boolean;
139+
140+
/**
141+
* Icon used for clearDate iconbutton. Defaults to RemoveEvent
142+
*/
143+
showClearDateIcon?: string;
134144
}

0 commit comments

Comments
 (0)