Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed children alignment issue #3656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = () => {
shreekeshmurkar marked this conversation as resolved.
Show resolved Hide resolved
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);
});
});
});