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

Ensure weekday labels respect the locale’s firstDayOfWeek #220

Merged
merged 4 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function Month({
<div className={ className }>
{React.cloneElement(captionElement, captionProps)}
<Weekdays
firstDayOfWeek={ firstDayOfWeek }
locale={ locale }
localeUtils={ localeUtils }
weekdayComponent={ weekdayComponent }
Expand Down
5 changes: 4 additions & 1 deletion src/Weekdays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import React, { PropTypes } from 'react';
import DayPickerPropTypes from './PropTypes';

export default function Weekdays({
firstDayOfWeek,
locale,
localeUtils,
weekdayComponent,
weekdayElement,
}) {
const days = [];
for (let i = 0; i < 7; i += 1) {
const weekday = (i + firstDayOfWeek) % 7;
const elementProps = {
key: i,
className: 'DayPicker-Weekday',
weekday: i,
weekday,
localeUtils,
locale,
};
Expand All @@ -32,6 +34,7 @@ export default function Weekdays({
}

Weekdays.propTypes = {
firstDayOfWeek: PropTypes.number.isRequired,
locale: PropTypes.string.isRequired,
localeUtils: DayPickerPropTypes.localeUtils.isRequired,
weekdayComponent: PropTypes.func,
Expand Down
6 changes: 6 additions & 0 deletions test/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { shallow, mount, render } from 'enzyme';
import { expect } from 'chai';
import sinon, { spy } from 'sinon';
import DayPicker from '../src/DayPicker';
import * as LocaleUtils from '../src/LocaleUtils';
import keys from '../src/keys';

describe('<DayPicker />', () => {
Expand Down Expand Up @@ -159,6 +160,11 @@ describe('<DayPicker />', () => {
);
expect(wrapper.find('.DayPicker-Day')).to.have.length(42);
});
it('should render weekday labels accounting for locale settings', () => {
const localeUtils = Object.assign({}, LocaleUtils, { getFirstDayOfWeek: () => 1 });
const wrapper = mount(<DayPicker localeUtils={ localeUtils } />);
expect(wrapper.find('.DayPicker-Weekday').at(0)).to.have.text('Mo');
});
});

describe('day modifiers', () => {
Expand Down