Skip to content

Commit f549112

Browse files
mgrdevportmartijnrusschen
authored andcommitted
Pass dateFormatCalendar to MonthDropdown to determine nominative or genitive display of month name (Hacker0x01#858)
1 parent 1ed8c16 commit f549112

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/calendar.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export default class Calendar extends React.Component {
236236
<MonthDropdown
237237
dropdownMode={this.props.dropdownMode}
238238
locale={this.props.locale}
239+
dateFormat={this.props.dateFormat}
239240
onChange={this.changeMonth}
240241
month={this.state.date.month()} />
241242
)

src/month_dropdown.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class MonthDropdown extends React.Component {
1010
static propTypes = {
1111
dropdownMode: PropTypes.oneOf(['scroll', 'select']).isRequired,
1212
locale: PropTypes.string,
13+
dateFormat: PropTypes.string.isRequired,
1314
month: PropTypes.number.isRequired,
1415
onChange: PropTypes.func.isRequired
1516
}
@@ -69,7 +70,7 @@ export default class MonthDropdown extends React.Component {
6970
render () {
7071
const localeData = moment.localeData(this.props.locale)
7172
const monthNames = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(
72-
(M) => localeData.months(moment({M}))
73+
(M) => localeData.months(moment({M}), this.props.dateFormat)
7374
)
7475

7576
let renderedDropdown

test/month_dropdown_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ describe('MonthDropdown', () => {
1414
let sandbox
1515

1616
function getMonthDropdown (overrideProps) {
17+
const dateFormatCalendar = 'MMMM YYYY'
1718
return mount(
1819
<MonthDropdown
1920
dropdownMode="scroll"
2021
month={11}
22+
dateFormat={dateFormatCalendar}
2123
onChange={mockHandleChange}
2224
{...overrideProps} />
2325
)
@@ -74,6 +76,21 @@ describe('MonthDropdown', () => {
7476
monthDropdown.find('.react-datepicker__month-option').at(2).simulate('click')
7577
expect(handleChangeResult).to.eq(2)
7678
})
79+
80+
it('should use dateFormat property to determine nominative or genitive display of month names', () => {
81+
let dropdownDateFormat = getMonthDropdown({dateFormat: 'DD/MM/YYYY'})
82+
expect(dropdownDateFormat.text()).to.contain('December')
83+
84+
dropdownDateFormat = getMonthDropdown({locale: 'el'})
85+
expect(dropdownDateFormat.text()).to.contain('Δεκέμβριος')
86+
dropdownDateFormat = getMonthDropdown({locale: 'el', showMonthDropwdown: true})
87+
expect(dropdownDateFormat.text()).to.contain('Δεκέμβριος')
88+
89+
dropdownDateFormat = getMonthDropdown({dateFormat: 'DMMMMYYYY', locale: 'el'})
90+
expect(dropdownDateFormat.text()).to.contain('Δεκεμβρίου')
91+
dropdownDateFormat = getMonthDropdown({dateFormat: 'DMMMMYYYY', locale: 'el', showMonthDropwdown: true})
92+
expect(dropdownDateFormat.text()).to.contain('Δεκεμβρίου')
93+
})
7794
})
7895

7996
describe('select mode', () => {

0 commit comments

Comments
 (0)