Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 8769fa2

Browse files
committed
adding a prop to allow disabling the month and year selectors
1 parent ccee480 commit 8769fa2

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ locale | Object | enUS from locale | you can vi
103103
className | String | | wrapper classname
104104
months | Number | 1 | rendered month count
105105
showSelectionPreview | Boolean | true | show preview on focused/hovered dates
106+
showMonthAndYearPickers | Boolean | true | show select tags for month and year on calendar top, if false it will just display the month and year
106107
rangeColors | String[] | | defines color for selection preview.
107108
shownDate | Date | | initial focus date
108109
minDate | Date | | defines minimum date. Disabled earlier dates
109110
maxDate | Date | | defines maximum date. Disabled later dates
110111
direction | String | 'vertical' | direction of calendar months. can be `vertical` or `horizontal`
111-
scroll | Object | { enabled: false }| infinite scroll behaviour configuration. Check out [Infinite Scroll](#infinite-scrolled-mode) section
112+
scroll | Object | { enabled: false }| infinite scroll behaviour configuration. Check out [Infinite Scroll](#infinite-scrolled-mode) section
112113
showMonthArrow | Boolean | true | show/hide month arrow button
113114
navigatorRenderer | Func | | renderer for focused date navigation area. fn(currentFocusedDate: Date, changeShownDate: func, props: object)
114115
ranges | *Object[] | [] | Defines ranges. array of range object
@@ -151,7 +152,7 @@ If you prefer, you can overwrite calendar sizes with `calendarWidth`/`calendarHe
151152
```js
152153
// shape of scroll prop
153154
scroll: {
154-
enabled: PropTypes.bool,
155+
enabled: PropTypes.bool,
155156
monthHeight: PropTypes.number,
156157
longMonthHeight: PropTypes.number, // some months has 1 more row than others
157158
monthWidth: PropTypes.number, // just used when direction="horizontal"

src/components/Calendar.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Calendar extends PureComponent {
161161
}
162162
}
163163
renderMonthAndYear(focusedDate, changeShownDate, props) {
164-
const { showMonthArrow, locale, minDate, maxDate } = props;
164+
const { showMonthArrow, locale, minDate, maxDate, showMonthAndYearPickers } = props;
165165
const upperYearLimit = maxDate.getFullYear();
166166
const lowerYearLimit = minDate.getFullYear();
167167
const styles = this.styles;
@@ -175,34 +175,42 @@ class Calendar extends PureComponent {
175175
<i />
176176
</button>
177177
) : null}
178-
<span className={styles.monthAndYearPickers}>
179-
<span className={styles.monthPicker}>
180-
<select
181-
value={focusedDate.getMonth()}
182-
onChange={e => changeShownDate(e.target.value, 'setMonth')}>
183-
{locale.localize.months().map((month, i) => (
184-
<option key={i} value={i}>
185-
{month}
186-
</option>
187-
))}
188-
</select>
189-
</span>
190-
<span className={styles.monthAndYearDivider} />
191-
<span className={styles.yearPicker}>
192-
<select
193-
value={focusedDate.getFullYear()}
194-
onChange={e => changeShownDate(e.target.value, 'setYear')}>
195-
{new Array(upperYearLimit - lowerYearLimit + 1).fill(upperYearLimit).map((val, i) => {
196-
const year = val - i;
197-
return (
198-
<option key={year} value={year}>
199-
{year}
178+
{showMonthAndYearPickers ? (
179+
<span className={styles.monthAndYearPickers}>
180+
<span className={styles.monthPicker}>
181+
<select
182+
value={focusedDate.getMonth()}
183+
onChange={e => changeShownDate(e.target.value, 'setMonth')}>
184+
{locale.localize.months().map((month, i) => (
185+
<option key={i} value={i}>
186+
{month}
200187
</option>
201-
);
202-
})}
203-
</select>
188+
))}
189+
</select>
190+
</span>
191+
<span className={styles.monthAndYearDivider} />
192+
<span className={styles.yearPicker}>
193+
<select
194+
value={focusedDate.getFullYear()}
195+
onChange={e => changeShownDate(e.target.value, 'setYear')}>
196+
{new Array(upperYearLimit - lowerYearLimit + 1)
197+
.fill(upperYearLimit)
198+
.map((val, i) => {
199+
const year = val - i;
200+
return (
201+
<option key={year} value={year}>
202+
{year}
203+
</option>
204+
);
205+
})}
206+
</select>
207+
</span>
208+
</span>
209+
) : (
210+
<span className={styles.monthAndYearPickers}>
211+
{locale.localize.months()[focusedDate.getMonth()]} {focusedDate.getFullYear()}
204212
</span>
205-
</span>
213+
)}
206214
{showMonthArrow ? (
207215
<button
208216
type="button"
@@ -447,6 +455,7 @@ class Calendar extends PureComponent {
447455

448456
Calendar.defaultProps = {
449457
showMonthArrow: true,
458+
showMonthAndYearPickers: true,
450459
classNames: {},
451460
locale: defaultLocale,
452461
ranges: [],
@@ -469,6 +478,7 @@ Calendar.defaultProps = {
469478

470479
Calendar.propTypes = {
471480
showMonthArrow: PropTypes.bool,
481+
showMonthAndYearPickers: PropTypes.bool,
472482
minDate: PropTypes.object,
473483
maxDate: PropTypes.object,
474484
date: PropTypes.object,

0 commit comments

Comments
 (0)