File tree Expand file tree Collapse file tree 7 files changed +83
-1
lines changed Expand file tree Collapse file tree 7 files changed +83
-1
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ import SelectsRange from "../../examples/selectsRange";
90
90
import selectsRangeWithDisabledDates from "../../examples/selectsRangeWithDisabledDates" ;
91
91
import CalendarStartDay from "../../examples/calendarStartDay" ;
92
92
import ExternalForm from "../../examples/externalForm" ;
93
+ import CalendarIcon from "../../examples/calendarIcon" ;
93
94
94
95
import "./style.scss" ;
95
96
import "react-datepicker/dist/react-datepicker.css" ;
@@ -105,6 +106,10 @@ export default class exampleComponents extends React.Component {
105
106
title : "Default" ,
106
107
component : Default ,
107
108
} ,
109
+ {
110
+ title : "Calendar Icon" ,
111
+ component : CalendarIcon ,
112
+ } ,
108
113
{
109
114
title : "Calendar container" ,
110
115
component : CalendarContainer ,
Original file line number Diff line number Diff line change
1
+ ( ) => {
2
+ const [ startDate , setStartDate ] = useState ( new Date ( ) ) ;
3
+ return (
4
+ < DatePicker
5
+ showIcon
6
+ selected = { startDate }
7
+ onChange = { ( date ) => setStartDate ( date ) }
8
+ />
9
+ ) ;
10
+ } ;
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ General datepicker component.
44
44
| ` injectTimes ` | ` array ` | | |
45
45
| ` inline ` | ` bool ` | | |
46
46
| ` isClearable ` | ` bool ` | | |
47
+ | ` showIcon ` | ` bool ` | | |
47
48
| ` locale ` | ` string ` | | |
48
49
| ` maxDate ` | ` instanceOf(Date) ` | | |
49
50
| ` maxTime ` | ` instanceOf(Date) ` | | |
Original file line number Diff line number Diff line change 52
52
| ` injectTimes ` | ` array ` | | |
53
53
| ` inline ` | ` bool ` | | |
54
54
| ` isClearable ` | ` bool ` | | |
55
+ | ` showIcon ` | ` bool ` | | |
55
56
| ` locale ` | ` union(string\|shape) ` | | |
56
57
| ` maxDate ` | ` instanceOfDate ` | | |
57
58
| ` maxTime ` | ` instanceOfDate ` | | |
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ export default class DatePicker extends React.Component {
181
181
injectTimes : PropTypes . array ,
182
182
inline : PropTypes . bool ,
183
183
isClearable : PropTypes . bool ,
184
+ showIcon : PropTypes . bool ,
184
185
locale : PropTypes . oneOfType ( [
185
186
PropTypes . string ,
186
187
PropTypes . shape ( { locale : PropTypes . object } ) ,
@@ -1176,8 +1177,22 @@ export default class DatePicker extends React.Component {
1176
1177
} ;
1177
1178
1178
1179
renderInputContainer ( ) {
1180
+ const { showIcon } = this . props ;
1179
1181
return (
1180
- < div className = "react-datepicker__input-container" >
1182
+ < div
1183
+ className = { `react-datepicker__input-container ${
1184
+ showIcon ? "react-datepicker__view-calendar-icon" : ""
1185
+ } `}
1186
+ >
1187
+ { showIcon && (
1188
+ < svg
1189
+ className = "react-datepicker__calendar-icon"
1190
+ xmlns = "http://www.w3.org/2000/svg"
1191
+ viewBox = "0 0 448 512"
1192
+ >
1193
+ < path d = "M96 32V64H48C21.5 64 0 85.5 0 112v48H448V112c0-26.5-21.5-48-48-48H352V32c0-17.7-14.3-32-32-32s-32 14.3-32 32V64H160V32c0-17.7-14.3-32-32-32S96 14.3 96 32zM448 192H0V464c0 26.5 21.5 48 48 48H400c26.5 0 48-21.5 48-48V192z" />
1194
+ </ svg >
1195
+ ) }
1181
1196
{ this . renderAriaLiveRegion ( ) }
1182
1197
{ this . renderDateInput ( ) }
1183
1198
{ this . renderClearButton ( ) }
Original file line number Diff line number Diff line change 517
517
position : relative ;
518
518
display : inline-block ;
519
519
width : 100% ;
520
+
521
+ .react-datepicker__calendar-icon {
522
+ position : absolute ;
523
+ padding : 0.5rem ;
524
+ }
525
+ }
526
+
527
+ .react-datepicker__view-calendar-icon {
528
+ input {
529
+ padding : 6px 10px 5px 25px ;
530
+ }
520
531
}
521
532
522
533
.react-datepicker__year-read-view ,
701
712
width : 1px ;
702
713
white-space : nowrap ;
703
714
}
715
+
716
+ .react-datepicker__calendar-icon {
717
+ width : 1em ;
718
+ height : 1em ;
719
+ vertical-align : -0.125em ;
720
+ }
Original file line number Diff line number Diff line change @@ -2092,4 +2092,37 @@ describe("DatePicker", () => {
2092
2092
) ;
2093
2093
} ) ;
2094
2094
} ) ;
2095
+
2096
+ it ( "should not customize the className attribute if showIcon is set to false" , ( ) => {
2097
+ let datePicker = TestUtils . renderIntoDocument (
2098
+ < DatePicker selected = { utils . newDate ( "2021-04-15" ) } />
2099
+ ) ;
2100
+ let showIconClass = TestUtils . findRenderedDOMComponentWithClass (
2101
+ datePicker ,
2102
+ "react-datepicker__input-container "
2103
+ ) . getAttribute ( "class" ) ;
2104
+ expect ( showIconClass ) . to . equal ( "react-datepicker__input-container " ) ;
2105
+ } ) ;
2106
+
2107
+ it ( "should display the Calendar icon if showIcon is set to true" , ( ) => {
2108
+ let datePicker = TestUtils . renderIntoDocument (
2109
+ < DatePicker selected = { utils . newDate ( "2021-04-15" ) } showIcon />
2110
+ ) ;
2111
+ let showIconClass = TestUtils . findRenderedDOMComponentWithClass (
2112
+ datePicker ,
2113
+ "react-datepicker__input-container"
2114
+ ) . getAttribute ( "class" ) ;
2115
+ expect ( showIconClass ) . to . equal (
2116
+ "react-datepicker__input-container react-datepicker__view-calendar-icon"
2117
+ ) ;
2118
+
2119
+ datePicker = TestUtils . renderIntoDocument (
2120
+ < DatePicker selected = { utils . newDate ( "2021-04-15" ) } showIcon />
2121
+ ) ;
2122
+ showIconClass = TestUtils . findRenderedDOMComponentWithClass (
2123
+ datePicker ,
2124
+ "react-datepicker__calendar-icon"
2125
+ ) . getAttribute ( "class" ) ;
2126
+ expect ( showIconClass ) . to . equal ( "react-datepicker__calendar-icon" ) ;
2127
+ } ) ;
2095
2128
} ) ;
You can’t perform that action at this time.
0 commit comments