Skip to content

Commit

Permalink
Merge pull request #3656 from shreekeshmurkar/children-position-fix
Browse files Browse the repository at this point in the history
fixed children alignment issue
  • Loading branch information
martijnrusschen committed Aug 24, 2022
2 parents 365ae03 + ee5adca commit ca3782d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,16 @@ export default class Calendar extends React.Component {
}
};

renderChildren = () => {
if (this.props.children) {
return (
<div className="react-datepicker__children-container">
{this.props.children}
</div>
);
}
};

render() {
const Container = this.props.container || CalendarContainer;
return (
Expand All @@ -996,7 +1006,7 @@ export default class Calendar extends React.Component {
{this.renderTodayButton()}
{this.renderTimeSection()}
{this.renderInputTimeSection()}
{this.props.children}
{this.renderChildren()}
</Container>
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions src/stylesheets/datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,11 @@
font-size: $datepicker__font-size * 1.8;
}
}

.react-datepicker__children-container {
width: 13.8rem;
margin: 0.4rem;
padding-right: 0.2rem;
padding-left: 0.2rem;
height: auto;
}
29 changes: 29 additions & 0 deletions test/calendar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1712,4 +1712,33 @@ describe("Calendar", function () {
expect(onKeyDownSpy.calledOnce).to.be.true;
});
});

describe("renderChildren", () => {
const renderCalendar = (props) =>
mount(
<Calendar
dateFormat={dateFormat}
onSelect={() => {}}
onClickOutside={() => {}}
hideCalendar={() => {}}
dropdownMode="scroll"
{...props}
/>
);
const childrenContainerSelector = ".react-datepicker__children-container";

it("should render children components", function () {
const calendar = renderCalendar({
children: <div>This is a child component for test.</div>,
});
const childrenContainer = calendar.find(childrenContainerSelector);
expect(childrenContainer).to.have.length(1);
});

it("should not render children components", function () {
const calendar = renderCalendar();
const childrenContainer = calendar.find(childrenContainerSelector);
expect(childrenContainer).to.have.length(0);
});
});
});

0 comments on commit ca3782d

Please sign in to comment.