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

Add option to disable calendar popover #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -116,6 +116,10 @@ DatePicker component. Renders as a [React-Bootstrap InputGroup](https://react-bo
* **Optional**
* **Type:** `bool`
* **Example:** `false`
* `calendarDisabled` - Whether or not the calendar popover will be disabled.
* **Optional**
* **Type:** `bool`
* **Example:** `false`
* `onChange` - Focus callback function.
* **Optional**
* **Type:** `function`
Expand Down
7 changes: 7 additions & 0 deletions example/app.jsx
Expand Up @@ -129,6 +129,13 @@ const App = createReactClass({
<HelpBlock>Help</HelpBlock>
</FormGroup>
</Col>
<Col sm={6}>
<FormGroup controlId="calendar_disabled">
<ControlLabel>Calendar Disabled</ControlLabel>
<DatePicker calendarDisabled={true} onChange={this.handleChange} placeholder="Placeholder" value={this.state.date} id="calendar_disabled_example" />
<HelpBlock>Help</HelpBlock>
</FormGroup>
</Col>
</Row>
<Row>
<Col xs={6}>
Expand Down
25 changes: 15 additions & 10 deletions src/index.jsx
Expand Up @@ -267,6 +267,7 @@ export default createReactClass({
onFocus: PropTypes.func,
autoFocus: PropTypes.bool,
disabled: PropTypes.bool,
calendarDisabled: PropTypes.bool,
weekStartsOnMonday: (props, propName, componentName) => {
if (props[propName]) {
return new Error(`Prop '${propName}' supplied to '${componentName}' is obsolete. Use 'weekStartsOn' instead.`);
Expand Down Expand Up @@ -328,6 +329,7 @@ export default createReactClass({
showClearButton: true,
autoFocus: false,
disabled: false,
calendarDisabled: false,
showTodayButton: false,
todayButtonLabel: 'Today',
autoComplete: 'on',
Expand Down Expand Up @@ -676,13 +678,8 @@ export default createReactClass({
noValidate={this.props.noValidate}
/>;

return <InputGroup
ref="inputGroup"
bsClass={this.props.showClearButton ? this.props.bsClass : ''}
bsSize={this.props.bsSize}
id={this.props.id ? `${this.props.id}_group` : null}>
{control}
<Overlay
const overlay = !this.props.calendarDisabled
&& <Overlay
rootClose={true}
onHide={this.handleHide}
show={this.state.focused}
Expand All @@ -704,10 +701,18 @@ export default createReactClass({
maxDate={this.props.maxDate}
roundedCorners={this.props.roundedCorners}
showWeeks={this.props.showWeeks}
/>
/>
</Popover>
</Overlay>
<div ref="overlayContainer" style={{position: 'relative'}} />
</Overlay>;

return <InputGroup
ref="inputGroup"
bsClass={this.props.showClearButton ? this.props.bsClass : ''}
bsSize={this.props.bsSize}
id={this.props.id ? `${this.props.id}_group` : null}>
{control}
{overlay}
{!this.props.calendarDisabled && <div ref="overlayContainer" style={{position: 'relative'}} />}
<input ref="hiddenInput" type="hidden" id={this.props.id} name={this.props.name} value={this.state.value || ''} data-formattedvalue={this.state.value ? this.state.inputValue : ''} />
{this.props.showClearButton && !this.props.customControl && <InputGroup.Addon
onClick={this.props.disabled ? null : this.clear}
Expand Down
18 changes: 18 additions & 0 deletions test/core.test.jsx
Expand Up @@ -623,6 +623,24 @@ describe("Date Picker", function() {
assertIsoStringsHaveSameDate(value, originalValue);
ReactDOM.unmountComponentAtNode(container);
}));
it("should disable the calendar.", co.wrap(function *(){
const id = UUID.v4();
const App = createReactClass({
render: function(){
return <div>
<DatePicker id={id} calendarDisabled={true} />
</div>;
}
});
yield new Promise(function(resolve, reject){
ReactDOM.render(<App />, container, resolve);
});
const inputElement = document.querySelector("input.form-control");
TestUtils.Simulate.focus(inputElement);
const popover = document.querySelector(".date-picker-popover");
assert.equal(popover, null);
ReactDOM.unmountComponentAtNode(container);
}));
it("should display the correct day of the week in the calendar.", co.wrap(function *(){
const id = UUID.v4();
let value = null;
Expand Down