Skip to content

Commit

Permalink
Merge pull request #1160 from airbnb/amh-make-nav-optional
Browse files Browse the repository at this point in the history
make nav buttons optional
  • Loading branch information
majapw authored May 14, 2018
2 parents 4e2db9d + e6c7872 commit dce2fc4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/DayPickerRangeControllerWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DayPickerRangeControllerWrapper extends React.Component {
const endDateString = endDate && endDate.format('YYYY-MM-DD');

return (
<div>
<div style={{ height: '100%' }}>
{showInputs &&
<div style={{ marginBottom: 16 }}>
<input type="text" name="start date" value={startDateString} readOnly />
Expand Down
7 changes: 7 additions & 0 deletions src/components/DayPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const propTypes = forbidExtraProps({
// navigation props
navPrev: PropTypes.node,
navNext: PropTypes.node,
noNavButtons: PropTypes.bool,
onPrevMonthClick: PropTypes.func,
onNextMonthClick: PropTypes.func,
onMultiplyScrollableMonths: PropTypes.func, // VERTICAL_SCROLLABLE daypickers only
Expand Down Expand Up @@ -122,6 +123,7 @@ export const defaultProps = {
// navigation props
navPrev: null,
navNext: null,
noNavButtons: false,
onPrevMonthClick() {},
onNextMonthClick() {},
onMultiplyScrollableMonths() {},
Expand Down Expand Up @@ -639,11 +641,16 @@ class DayPicker extends React.Component {
const {
navPrev,
navNext,
noNavButtons,
orientation,
phrases,
isRTL,
} = this.props;

if (noNavButtons) {
return null;
}

let onNextMonthClick;
if (orientation === VERTICAL_SCROLLABLE) {
onNextMonthClick = this.multiplyScrollableMonths;
Expand Down
4 changes: 4 additions & 0 deletions src/components/DayPickerRangeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const propTypes = forbidExtraProps({

navPrev: PropTypes.node,
navNext: PropTypes.node,
noNavButtons: PropTypes.bool,

onPrevMonthClick: PropTypes.func,
onNextMonthClick: PropTypes.func,
Expand Down Expand Up @@ -128,6 +129,7 @@ const defaultProps = {

navPrev: null,
navNext: null,
noNavButtons: false,

onPrevMonthClick() {},
onNextMonthClick() {},
Expand Down Expand Up @@ -990,6 +992,7 @@ export default class DayPickerRangeController extends React.Component {
renderMonth,
navPrev,
navNext,
noNavButtons,
onOutsideClick,
withPortal,
enableOutsideDays,
Expand Down Expand Up @@ -1037,6 +1040,7 @@ export default class DayPickerRangeController extends React.Component {
onOutsideClick={onOutsideClick}
navPrev={navPrev}
navNext={navNext}
noNavButtons={noNavButtons}
renderCalendarDay={renderCalendarDay}
renderDayContents={renderDayContents}
renderCalendarInfo={renderCalendarInfo}
Expand Down
20 changes: 19 additions & 1 deletion stories/DayPickerRangeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import InfoPanelDecorator, { monospace } from './InfoPanelDecorator';
import isSameDay from '../src/utils/isSameDay';
import isInclusivelyAfterDay from '../src/utils/isInclusivelyAfterDay';

import { VERTICAL_ORIENTATION } from '../src/constants';
import { VERTICAL_ORIENTATION, VERTICAL_SCROLLABLE } from '../src/constants';

import DayPickerRangeControllerWrapper from '../examples/DayPickerRangeControllerWrapper';

Expand Down Expand Up @@ -164,6 +164,18 @@ storiesOf('DayPickerRangeController', module)
orientation={VERTICAL_ORIENTATION}
/>
))
.addWithInfo('vertical scrollable', () => (
<div style={{ height: 300 }}>
<DayPickerRangeControllerWrapper
onOutsideClick={action('DayPickerRangeController::onOutsideClick')}
onPrevMonthClick={action('DayPickerRangeController::onPrevMonthClick')}
onNextMonthClick={action('DayPickerRangeController::onNextMonthClick')}
orientation={VERTICAL_SCROLLABLE}
numberOfMonths={6}
verticalHeight={800}
/>
</div>
))
.addWithInfo('with custom month navigation', () => (
<DayPickerRangeControllerWrapper
onOutsideClick={action('DayPickerRangeController::onOutsideClick')}
Expand Down Expand Up @@ -286,4 +298,10 @@ storiesOf('DayPickerRangeController', module)
onNextMonthClick={action('DayPickerRangeController::onNextMonthClick')}
verticalBorderSpacing={16}
/>
))
.addWithInfo('with no nav buttons', () => (
<DayPickerRangeControllerWrapper
onOutsideClick={action('DayPickerRangeController::onOutsideClick')}
noNavButtons
/>
));
13 changes: 13 additions & 0 deletions test/components/DayPickerRangeController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { shallow } from 'enzyme';
import DayPickerRangeController from '../../src/components/DayPickerRangeController';

import DayPicker from '../../src/components/DayPicker';
import DayPickerNavigation from '../../src/components/DayPickerNavigation';

import toISODateString from '../../src/utils/toISODateString';
import toISOMonthString from '../../src/utils/toISOMonthString';
Expand Down Expand Up @@ -3215,5 +3216,17 @@ describe('DayPickerRangeController', () => {
expect(wrapper.instance().isLastDayOfWeek(moment().startOf('week').add(1, 'day'))).to.equal(false);
});
});

describe('noNavButtons prop', () => {
it('renders navigation button', () => {
const wrapper = shallow(<DayPickerRangeController />).dive().dive();
expect(wrapper.find(DayPickerNavigation)).to.have.lengthOf(1);
});

it('does not render navigation button when noNavButtons prop applied', () => {
const wrapper = shallow(<DayPickerRangeController noNavButtons />).dive().dive();
expect(wrapper.find(DayPickerNavigation)).to.have.lengthOf(0);
});
});
});
});

0 comments on commit dce2fc4

Please sign in to comment.