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

STCOM-1395 Datepicker - update Calendar cursorDate when year is changed #2410

Merged
merged 3 commits into from
Jan 7, 2025
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Clear filter value after an action chosen from `MultiSelection` menu. Refs STCOM-1385.
* ExportCSV - fix usage within `<Modal>`s by rendering the download link to the `div#OverlayContainer`. Refs STCOM-1387.
* `<MenuSection>` should default its heading/label tag to `H3` instead of `H1`. Refs STCOM-1392.
* `<Datepicker>` fix for `<Calendar>` tabIndex when changing the year. Refs STCOM-1395.
* `<Tooltip>` should allow for tooltip content to be hovered without closing the tooltip. Refs STCOM-1391.
* `<AdvancedSearchRow>` - change `aria-label` for the input box to enter a search query and the Boolean operator dropdown. Refs STCOM-1195.

Expand Down
14 changes: 12 additions & 2 deletions lib/Datepicker/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,20 @@ class Calendar extends React.Component {
if (e.target.value) {
const year = e.target.value;
if (new moment(year, 'YYYY', true).isValid()) { // eslint-disable-line new-cap
this.setState(curState => ({
this.setState(curState => {
let cursorDate = '';
if (year === this.selectedMoment?.year()) {
cursorDate = this.selectedMoment;
} else {
cursorDate = new moment().year(year).date(1).month(curState.month); // eslint-disable-line new-cap
}
return {
year,
calendar: getCalendar(year, curState.month, curState.dayOffset),
}));
cursorDate,
};
}
);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions lib/Datepicker/tests/Datepicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Datepicker', () => {
.locator((el) => el.textContent)
.filters({
month: (el) => el.getAttribute('data-date').split('/')[0],
tabIndex: (el) => el.tabIndex,
});

describe('render', () => {
Expand All @@ -69,6 +70,31 @@ describe('Datepicker', () => {
it('has a placeholder in the input', () => datepicker.has({ placeholder: 'MM/DD/YYYY' }));
});

describe('calendar tabIndex', () => {
beforeEach(async () => {
await mountWithContext(
<Datepicker onChange={() => {}} />
);
await datepicker.openCalendar();
});

describe('changing the month', () => {
beforeEach(async () => {
await month.choose('June');
});

it('calendar days have a tabIndex 0 day', () => CalendarDays({ tabIndex: 0 }).exists());
});

describe('changing the year', () => {
beforeEach(async () => {
await calendar.setYear('2012');
});

it('calendar days have a tabIndex 0 day', () => CalendarDays({ tabIndex: 0 }).exists());
});
});

describe('exclude functionality', () => {
let changed;
beforeEach(async () => {
Expand Down
Loading