Skip to content

Commit

Permalink
add wrapperClassName and add width style 100% (#1557)
Browse files Browse the repository at this point in the history
* add wrapperClassName and add width style 100%

* revert some unnessary changes

* enlarge time container to zh locale

* fix duplicate isValidDateSelection
  • Loading branch information
mtiger2k authored and martijnrusschen committed Aug 12, 2019
1 parent 65f1e0f commit 6a3280e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default class DatePicker extends React.Component {
timeInputLabel: PropTypes.string,
renderCustomHeader: PropTypes.func,
renderDayContents: PropTypes.func,
wrapperClassName: PropTypes.string,
inlineFocusSelectedMonth: PropTypes.bool,
onDayMouseEnter: PropTypes.func,
onMonthMouseLeave: PropTypes.func
Expand Down Expand Up @@ -200,6 +201,7 @@ export default class DatePicker extends React.Component {
previousMonthButtonLabel: "Previous Month",
nextMonthButtonLabel: "Next month",
timeInputLabel: "Time",

renderDayContents(date) {
return date;
},
Expand Down Expand Up @@ -246,10 +248,10 @@ export default class DatePicker extends React.Component {
this.props.openToDate
? this.props.openToDate
: this.props.selectsEnd && this.props.startDate
? this.props.startDate
: this.props.selectsStart && this.props.endDate
? this.props.endDate
: newDate();
? this.props.startDate
: this.props.selectsStart && this.props.endDate
? this.props.endDate
: newDate();

calcInitialState = () => {
const defaultPreSelection = this.getPreSelection();
Expand All @@ -259,8 +261,8 @@ export default class DatePicker extends React.Component {
minDate && isBefore(defaultPreSelection, minDate)
? minDate
: maxDate && isAfter(defaultPreSelection, maxDate)
? maxDate
: defaultPreSelection;
? maxDate
: defaultPreSelection;
return {
open: this.props.startOpen || false,
preventFocus: false,
Expand Down Expand Up @@ -703,8 +705,8 @@ export default class DatePicker extends React.Component {
typeof this.props.value === "string"
? this.props.value
: typeof this.state.inputValue === "string"
? this.state.inputValue
: safeDateFormat(this.props.selected, this.props);
? this.state.inputValue
: safeDateFormat(this.props.selected, this.props);

return React.cloneElement(customInput, {
[customInputRef]: input => {
Expand Down Expand Up @@ -772,6 +774,7 @@ export default class DatePicker extends React.Component {
return (
<PopperComponent
className={this.props.popperClassName}
wrapperClassName={this.props.wrapperClassName}
hidePopper={!this.isCalendarOpen()}
popperModifiers={this.props.popperModifiers}
targetComponent={
Expand Down
9 changes: 8 additions & 1 deletion src/popper_component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const popperPlacementPositions = placements;
export default class PopperComponent extends React.Component {
static propTypes = {
className: PropTypes.string,
wrapperClassName: PropTypes.string,
hidePopper: PropTypes.bool,
popperComponent: PropTypes.element,
popperModifiers: PropTypes.object, // <datepicker/> props
Expand Down Expand Up @@ -35,6 +36,7 @@ export default class PopperComponent extends React.Component {
render() {
const {
className,
wrapperClassName,
hidePopper,
popperComponent,
popperModifiers,
Expand Down Expand Up @@ -70,11 +72,16 @@ export default class PopperComponent extends React.Component {
popper = React.createElement(this.props.popperContainer, {}, popper);
}

const wrapperClasses = classnames(
"react-datepicker-wrapper",
wrapperClassName
);

return (
<Manager>
<Reference>
{({ ref }) => (
<div ref={ref} className="react-datepicker-wrapper">
<div ref={ref} className={wrapperClasses}>
{targetComponent}
</div>
)}
Expand Down
7 changes: 5 additions & 2 deletions src/stylesheets/datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

.react-datepicker-wrapper {
display: inline-block;
padding: 0;
border: 0;
}

.react-datepicker {
Expand Down Expand Up @@ -244,7 +246,7 @@
.react-datepicker__time-container {
float: right;
border-left: 1px solid $datepicker__border-color;
width: 70px;
width: 85px;

&--with-today-button {
display: inline;
Expand All @@ -260,7 +262,7 @@
background: white;

.react-datepicker__time-box {
width: 70px;
width: 85px;
overflow-x: hidden;
margin: 0 auto;
text-align: center;
Expand Down Expand Up @@ -446,6 +448,7 @@
.react-datepicker__input-container {
position: relative;
display: inline-block;
width: 100%;
}

.react-datepicker__year-read-view,
Expand Down

0 comments on commit 6a3280e

Please sign in to comment.