Skip to content

Commit

Permalink
Fix logic for apply default navigation button styling
Browse files Browse the repository at this point in the history
  • Loading branch information
nkinser committed Jan 14, 2020
1 parent 48f7cd3 commit 4c67f2b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/DayPickerNavigation.jsx
Expand Up @@ -97,7 +97,7 @@ function DayPickerNavigation({
let navPrevTabIndex = {};
let navNextTabIndex = {};

if (!navPrevIcon) {
if (!navPrevIcon && !renderNavPrevButton) {
navPrevTabIndex = { tabIndex: '0' };
isDefaultNavPrev = true;
let Icon = isVertical ? ChevronUp : LeftArrow;
Expand All @@ -115,7 +115,7 @@ function DayPickerNavigation({
);
}

if (!navNextIcon) {
if (!navNextIcon && !renderNavNextButton) {
navNextTabIndex = { tabIndex: '0' };
isDefaultNavNext = true;
let Icon = isVertical ? ChevronDown : RightArrow;
Expand Down
62 changes: 62 additions & 0 deletions stories/DayPickerRangeController.js
Expand Up @@ -157,6 +157,54 @@ function renderNavNextButton(buttonProps) {
);
}

function renderNavPrevButtonForVerticalScrollable(buttonProps) {
const {
ariaLabel,
disabled,
onClick,
onKeyUp,
onMouseUp,
} = buttonProps;

return (
<button
aria-label={ariaLabel}
disabled={disabled}
onClick={onClick}
onKeyUp={onKeyUp}
onMouseUp={onMouseUp}
style={{ width: '100%', textAlign: 'center' }}
type="button"
>
&lsaquo; Prev
</button>
);
}

function renderNavNextButtonForVerticalScrollable(buttonProps) {
const {
ariaLabel,
disabled,
onClick,
onKeyUp,
onMouseUp,
} = buttonProps;

return (
<button
aria-label={ariaLabel}
disabled={disabled}
onClick={onClick}
onKeyUp={onKeyUp}
onMouseUp={onMouseUp}
style={{ width: '100%', textAlign: 'center' }}
type="button"
>
Next &rsaquo;
</button>
);
}

function renderKeyboardShortcutsButton(buttonProps) {
const { ref, onClick, ariaLabel } = buttonProps;

Expand Down Expand Up @@ -462,6 +510,20 @@ storiesOf('DayPickerRangeController', module)
/>
</div>
)))
.add('vertical scrollable with custom rendered month navigation', withInfo()(() => (
<div style={{ height: 500 }}>
<DayPickerRangeControllerWrapper
onOutsideClick={action('DayPickerRangeController::onOutsideClick')}
onPrevMonthClick={action('DayPickerRangeController::onPrevMonthClick')}
onNextMonthClick={action('DayPickerRangeController::onNextMonthClick')}
orientation={VERTICAL_SCROLLABLE}
numberOfMonths={3}
verticalHeight={300}
renderNavPrevButton={renderNavPrevButtonForVerticalScrollable}
renderNavNextButton={renderNavNextButtonForVerticalScrollable}
/>
</div>
)))
.add('with custom month navigation icons', withInfo()(() => (
<DayPickerRangeControllerWrapper
onOutsideClick={action('DayPickerRangeController::onOutsideClick')}
Expand Down

0 comments on commit 4c67f2b

Please sign in to comment.