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

Fix #4420: Update home key and end key navigation in Calendar component #4430

Merged
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
11 changes: 7 additions & 4 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import {
addDays,
addMonths,
addWeeks,
addYears,
subDays,
subMonths,
subWeeks,
subYears,
isDayDisabled,
isDayInRange,
getEffectiveMinDate,
Expand All @@ -38,6 +36,7 @@ import {
getYear,
getMonth,
getStartOfWeek,
getEndOfWeek,
registerLocale,
setDefaultLocale,
getDefaultLocale,
Expand Down Expand Up @@ -883,10 +882,14 @@ export default class DatePicker extends React.Component {
newSelection = addMonths(copy, 1);
break;
case "Home":
newSelection = subYears(copy, 1);
newSelection = getStartOfWeek(
copy,
this.props.locale,
this.props.calendarStartDay,
);
break;
case "End":
newSelection = addYears(copy, 1);
newSelection = getEndOfWeek(copy);
break;
default:
newSelection = null;
Expand Down
23 changes: 4 additions & 19 deletions test/datepicker_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,25 +932,25 @@ describe("DatePicker", () => {
).toBe(utils.formatDate(data.copyM, data.testFormat));
});
it("should handle onDayKeyDown End", () => {
var data = getOnInputKeyDownStuff();
const data = getOnInputKeyDownStuff();
TestUtils.Simulate.keyDown(data.nodeInput, getKey("ArrowDown"));
TestUtils.Simulate.keyDown(
getSelectedDayNode(data.datePicker),
getKey("End"),
);
data.copyM = utils.addYears(data.copyM, 1);
data.copyM = utils.getEndOfWeek(data.copyM);
expect(
utils.formatDate(data.datePicker.state.preSelection, data.testFormat),
).toBe(utils.formatDate(data.copyM, data.testFormat));
});
it("should handle onDayKeyDown Home", () => {
var data = getOnInputKeyDownStuff();
const data = getOnInputKeyDownStuff();
TestUtils.Simulate.keyDown(data.nodeInput, getKey("ArrowDown"));
TestUtils.Simulate.keyDown(
getSelectedDayNode(data.datePicker),
getKey("Home"),
);
data.copyM = utils.subYears(data.copyM, 1);
data.copyM = utils.getStartOfWeek(data.copyM);
expect(
utils.formatDate(data.datePicker.state.preSelection, data.testFormat),
).toBe(utils.formatDate(data.copyM, data.testFormat));
Expand Down Expand Up @@ -2117,21 +2117,6 @@ describe("DatePicker", () => {
);
expect(datePickerInline.state.shouldFocusDayInline).toBe(true);
});

it("should be set to true when changing displayed month with End key", () => {
const datePickerInline = TestUtils.renderIntoDocument(
<DatePicker
selected={utils.newDate("2020-11-15")}
dateFormat={dateFormat}
inline
/>,
);
TestUtils.Simulate.keyDown(
getSelectedDayNode(datePickerInline),
getKey("End"),
);
expect(datePickerInline.state.shouldFocusDayInline).toBe(true);
});
});

it("should show the correct start of week for GB locale", () => {
Expand Down
Loading