disabledSeconds: PropTypes.func,
onCurrentSelectPanelChange: PropTypes.func,
use12Hours: PropTypes.bool,
+ isAM: PropTypes.bool,
};
onItemChange = (type, itemValue) => {
if (type === 'hour') {
if (use12Hours) {
- if (this.isAM()) {
+ if (this.props.isAM) {
value.hour(+itemValue % 12);
} else {
value.hour((+itemValue % 12) + 12);
if (!showHour) {
return null;
}
- let disabledOptions = disabledHours();
+ const disabledOptions = disabledHours();
let hourOptionsAdj;
let hourAdj;
if (use12Hours) {
hourOptionsAdj = [12].concat(hourOptions.filter(h => h < 12 && h > 0));
hourAdj = (hour % 12) || 12;
-
- if (Array.isArray(disabledOptions)) {
- if (this.isAM()) {
- disabledOptions = disabledOptions.filter(h => h < 12).map(h => (h === 0 ? 12 : h));
- } else {
- disabledOptions = disabledOptions.map(h => (h === 12 ? 12 : h - 12));
- }
- }
} else {
hourOptionsAdj = hourOptions;
hourAdj = hour;
.map(c => format.match(/\sA/) ? c.toUpperCase() : c)
.map(c => ({ value: c }));
- const selected = this.isAM() ? 0 : 1;
+ const selected = this.props.isAM ? 0 : 1;
return (
<Select
);
}
- isAM() {
- const value = (this.props.value || this.props.defaultOpenValue);
- return value.hour() >= 0 && value.hour() < 12;
- }
-
render() {
const { prefixCls, defaultOpenValue } = this.props;
const value = this.props.value || defaultOpenValue;
this.props.onEsc();
}
+ disabledHours = () => {
+ const { use12Hours, disabledHours } = this.props;
+ let disabledOptions = disabledHours();
+ if (use12Hours && Array.isArray(disabledOptions)) {
+ if (this.isAM()) {
+ disabledOptions = disabledOptions.filter(h => h < 12).map(h => (h === 0 ? 12 : h));
+ } else {
+ disabledOptions = disabledOptions.map(h => (h === 12 ? 12 : h - 12));
+ }
+ }
+ return disabledOptions;
+ }
+
+ isAM() {
+ const value = (this.state.value || this.props.defaultOpenValue);
+ return value.hour() >= 0 && value.hour() < 12;
+ }
+
render() {
const {
- prefixCls, className, placeholder, disabledHours, disabledMinutes,
+ prefixCls, className, placeholder, disabledMinutes,
disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly,
const {
value, currentSelectPanel,
} = this.state;
- const disabledHourOptions = disabledHours();
+ const disabledHourOptions = this.disabledHours();
const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null);
const disabledSecondOptions = disabledSeconds(value ? value.hour() : null,
value ? value.minute() : null);
hourOptions={hourOptions}
minuteOptions={minuteOptions}
secondOptions={secondOptions}
- disabledHours={disabledHours}
+ disabledHours={this.disabledHours}
disabledMinutes={disabledMinutes}
disabledSeconds={disabledSeconds}
onChange={this.onChange}
hourOptions={hourOptions}
minuteOptions={minuteOptions}
secondOptions={secondOptions}
- disabledHours={disabledHours}
+ disabledHours={this.disabledHours}
disabledMinutes={disabledMinutes}
disabledSeconds={disabledSeconds}
onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
use12Hours={use12Hours}
+ isAM={this.isAM()}
/>
{addon(this)}
</div>