Skip to content

Commit 57bb367

Browse files
committed
Disabled state.
1 parent 1744417 commit 57bb367

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

example/app.jsx

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,26 @@ const App = React.createClass({
5050
</Col>
5151
</Row>
5252
<Row>
53-
<Col xs={12}>
53+
<Col xs={6}>
5454
<h2>Change Handler</h2>
5555
</Col>
56+
<Col xs={6}>
57+
<h2>Disabled</h2>
58+
</Col>
5659
</Row>
5760
<Row>
5861
<Col sm={6}>
5962
<FormGroup controlId="change_handler">
63+
<ControlLabel>Change Handler</ControlLabel>
6064
<DatePicker onChange={this.handleChange} placeholder="Placeholder" value={this.state.date} id="change_handler_example" />
65+
<HelpBlock>Help</HelpBlock>
66+
</FormGroup>
67+
</Col>
68+
<Col sm={6}>
69+
<FormGroup controlId="disabled">
70+
<ControlLabel>Disabled</ControlLabel>
71+
<DatePicker disabled={true} onChange={this.handleChange} placeholder="Placeholder" value={this.state.date} id="disabled_example" />
72+
<HelpBlock>Help</HelpBlock>
6173
</FormGroup>
6274
</Col>
6375
</Row>
@@ -147,35 +159,44 @@ const App = React.createClass({
147159
</Col>
148160
</Row>
149161
<Row>
150-
<Col sm={3}>
151-
<FormGroup>
152-
<ControlLabel>Clear Button</ControlLabel>
153-
<DatePicker placeholder="Placeholder" clearButtonElement={<Glyphicon glyph="star" />} />
154-
<HelpBlock>Help</HelpBlock>
155-
</FormGroup>
156-
</Col>
157-
<Col sm={3}>
162+
<Col sm={4}>
158163
<FormGroup>
159164
<ControlLabel>Previous / Next Buttons</ControlLabel>
160165
<DatePicker placeholder="Placeholder" previousButtonElement={<Glyphicon glyph="star" />} nextButtonElement={<Glyphicon glyph="star" />} />
161166
<HelpBlock>Help</HelpBlock>
162167
</FormGroup>
163168
</Col>
164-
<Col sm={3}>
169+
<Col sm={4}>
165170
<FormGroup>
166171
<ControlLabel>Padding</ControlLabel>
167172
<DatePicker placeholder="Placeholder" cellPadding="10px" />
168173
<HelpBlock>Help</HelpBlock>
169174
</FormGroup>
170175
</Col>
171-
<Col sm={3}>
176+
<Col sm={4}>
172177
<FormGroup>
173178
<ControlLabel>Day and Month Labels</ControlLabel>
174179
<DatePicker placeholder="Placeholder" dayLabels={spanishDayLabels} monthLabels={spanishMonthLabels} />
175180
<HelpBlock>Help</HelpBlock>
176181
</FormGroup>
177182
</Col>
178183
</Row>
184+
<Row>
185+
<Col sm={6}>
186+
<FormGroup>
187+
<ControlLabel>Clear Button</ControlLabel>
188+
<DatePicker placeholder="Placeholder" clearButtonElement={<Glyphicon glyph="star" />} />
189+
<HelpBlock>Help</HelpBlock>
190+
</FormGroup>
191+
</Col>
192+
<Col sm={6}>
193+
<FormGroup controlId="no_clear_button">
194+
<ControlLabel>No Clear Button</ControlLabel>
195+
<DatePicker placeholder="Placeholder" showClearButton={false} />
196+
<HelpBlock>Help</HelpBlock>
197+
</FormGroup>
198+
</Col>
199+
</Row>
179200
<Row>
180201
<Col xs={12}>
181202
<h2>Placement</h2>
@@ -289,19 +310,6 @@ const App = React.createClass({
289310
</FormGroup>
290311
</Col>
291312
</Row>
292-
<Row>
293-
<Col xs={12}>
294-
<h2>No clear button visible</h2>
295-
</Col>
296-
</Row>
297-
<Row>
298-
<Col sm={6}>
299-
<FormGroup controlId="no_clear_button">
300-
<DatePicker placeholder="Placeholder" value={this.state.date}
301-
id="no_clear_button_example" showClearButton={false}/>
302-
</FormGroup>
303-
</Col>
304-
</Row>
305313
</Grid>;
306314
}
307315
});

src/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export default React.createClass({
123123
monthLabels: React.PropTypes.array,
124124
onChange: React.PropTypes.func,
125125
onClear: React.PropTypes.func,
126+
disabled: React.PropTypes.bool,
126127
weekStartsOnMonday: React.PropTypes.bool,
127128
clearButtonElement: React.PropTypes.oneOfType([
128129
React.PropTypes.string,
@@ -156,6 +157,7 @@ export default React.createClass({
156157
calendarPlacement: "bottom",
157158
dateFormat: dateFormat,
158159
showClearButton: true,
160+
disabled: false
159161
}
160162
},
161163
getInitialState() {
@@ -399,13 +401,14 @@ export default React.createClass({
399401
value={this.state.inputValue || ''}
400402
ref="input"
401403
type="text"
404+
disabled={this.props.disabled}
402405
placeholder={this.state.focused ? this.props.dateFormat : this.state.placeholder}
403406
onFocus={this.handleFocus}
404407
onBlur={this.handleBlur}
405408
onChange={this.handleInputChange}
406409
style={{width: "100%"}}
407410
/>
408-
{this.props.showClearButton && <InputGroup.Addon onClick={this.clear} style={{cursor:this.state.inputValue ? "pointer" : "not-allowed"}}>{this.props.clearButtonElement}</InputGroup.Addon>}
411+
{this.props.showClearButton && <InputGroup.Addon onClick={this.props.disabled ? null : this.clear} style={{cursor:(this.state.inputValue && !this.props.disabled) ? "pointer" : "not-allowed"}}><div style={{opacity: (this.state.inputValue && !this.props.disabled) ? 1 : 0.5}}>{this.props.clearButtonElement}</div></InputGroup.Addon>}
409412
</InputGroup>;
410413
}
411414
});

0 commit comments

Comments
 (0)