Skip to content

Commit

Permalink
fix: Fix tabindex does not update accordingly with focused date
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Mar 9, 2020
1 parent 97c213e commit 02ff148
Show file tree
Hide file tree
Showing 38 changed files with 61 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,18 +828,20 @@ export class Datepicker extends LitElement {

const calendarAriaId = `calendarcaption${ci}`;
const midCalendarFullDate = calendar[1][1].fullDate;
const $newFocusedDate: Date = ci === 1 ?
computeNextFocusedDate({
disabledDaysSet,
disabledDatesSet,
hasAltKey: false,
keyCode: KEY_CODES_MAP.HOME,
focusedDate: $focusedDate,
selectedDate: $selectedDate,
minTime: +$min,
maxTime: +$max,
}) :
new Date('lol');
const isMidCalendar = ci === 1;
const $newFocusedDate: Date =
isMidCalendar && !this._isInVisibleMonth($focusedDate, $selectedDate) ?
computeNextFocusedDate({
disabledDaysSet,
disabledDatesSet,
hasAltKey: false,
keyCode: KEY_CODES_MAP.HOME,
focusedDate: $focusedDate,
selectedDate: $selectedDate,
minTime: +$min,
maxTime: +$max,
}) :
$focusedDate;

return html`
<div class="calendar-container" part="calendar">
Expand Down Expand Up @@ -879,12 +881,11 @@ export class Datepicker extends LitElement {
const curTime = +new Date(fullDate!);
const isCurrentDate = +$focusedDate === curTime;
const shouldTab = ci === 1 && $newFocusedDate ?
$newFocusedDate.getUTCDate() === Number(value) :
false;
const shouldTab = isMidCalendar && $newFocusedDate.getUTCDate() === Number(value);
return html`
<td
tabindex="${shouldTab ? '0' : '-1'}"
class="${classMap({
'full-calendar__day': true,
'day--disabled': disabled,
Expand All @@ -893,7 +894,6 @@ export class Datepicker extends LitElement {
})}"
part="calendar-day"
role="gridcell"
tabindex="${shouldTab ? '0' : '-1'}"
aria-disabled="${disabled ? 'true' : 'false'}"
aria-label="${label}"
aria-selected="${isCurrentDate ? 'true' : 'false'}"
Expand Down
45 changes: 45 additions & 0 deletions src/tests/app-datepicker/keyboards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { interaction } from '../helpers/interaction.js';
import { prettyHtml } from '../helpers/pretty-html.js';
import { toSelector } from '../helpers/to-selector.js';
import {
deepStrictEqual,
strictEqual,
} from '../helpers/typed-assert.js';

Expand Down Expand Up @@ -583,4 +584,48 @@ describe('keyboards', () => {
`);
});

it(`updates 'tabindex' on all affected dates (ArrowLeft)`, async () => {
const focusedDateSelector = toSelector('.day--focused');
const getFocusedDate = (s: string): Promise<string> =>
browser.executeAsync(async (a, b, done) => {
const n = document.body.querySelector<Datepicker>(a)!;

done(n.shadowRoot?.querySelector<HTMLTableCellElement>(b)?.outerHTML ?? '');
}, DATEPICKER_NAME, s);

const initialFocusedDateContent = await getFocusedDate(focusedDateSelector);

await focusCalendarsContainer();
await browserKeys(KEY_CODES_MAP.ARROW_LEFT);

const [
oldFocusedDateContent,
newFocusedDateContent,
]: [string, string] = await Promise.all([
getFocusedDate(toSelector(`[aria-label="Feb 20, 2020"]`)),
getFocusedDate(focusedDateSelector),
]);

deepStrictEqual(
[
initialFocusedDateContent,
oldFocusedDateContent,
].map(n => cleanHtml(n, { showTabindex: true })),
['0', '-1'].map((n) => {
const isTab = '0' === n;

return prettyHtml(`
<td tabindex="${n}" class="full-calendar__day${isTab ? ' day--focused' : ''}" aria-disabled="false" aria-label="Feb 20, 2020" aria-selected="${isTab ? 'true' : 'false'}">
<div class="calendar-day">20</div>
</td>
`);
})
);
strictEqual(cleanHtml(newFocusedDateContent, { showTabindex: true }), prettyHtml`
<td tabindex="0" class="full-calendar__day day--focused" aria-disabled="false" aria-label="Feb 19, 2020" aria-selected="true">
<div class="calendar-day">19</div>
</td>
`);
});

});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/attributes-0-Safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/attributes-0-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/attributes-1-Safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/attributes-1-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/properties-0-Safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/properties-0-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/properties-1-Safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker-dialog/properties-1-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-0-MicrosoftEdge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-0-Safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-0-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-0-firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-1-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/attributes-1-firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/tests/snapshots/app-datepicker/properties-0-MicrosoftEdge.png
Binary file modified src/tests/snapshots/app-datepicker/properties-0-Safari.png
Binary file modified src/tests/snapshots/app-datepicker/properties-0-chrome.png
Binary file modified src/tests/snapshots/app-datepicker/properties-1-chrome.png
Binary file modified src/tests/snapshots/app-datepicker/properties-1-firefox.png
Binary file modified src/tests/snapshots/app-datepicker/timezones-chrome.png
Binary file modified src/tests/snapshots/app-datepicker/timezones-firefox.png

0 comments on commit 02ff148

Please sign in to comment.