Skip to content

Commit

Permalink
Fix accessibility violations for the date picker (#2088)
Browse files Browse the repository at this point in the history
* Fix accessibility violations for the date picker

* Add i18n for date picker
  • Loading branch information
stevekinney authored May 6, 2024
1 parent fc3e260 commit 2b8b941
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
34 changes: 19 additions & 15 deletions src/lib/holocene/calendar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@

<div class="row">
{#each cells as { allowed, value }, index (index)}
<button
type="button"
on:click={allowed && value ? () => onChange(value) : noop}
class="cell"
class:highlight={allowed && value}
class:disabled={!allowed}
class:selected={new Date(
date.getFullYear(),
date.getMonth(),
date.getDate(),
).getTime() === new Date(year, month, value).getTime()}
>
{value || ''}
</button>
{#if value}
<button
type="button"
on:click={allowed && value ? () => onChange(value) : noop}
class="cell"
class:highlight={allowed && value}
class:disabled={!allowed}
class:selected={new Date(
date.getFullYear(),
date.getMonth(),
date.getDate(),
).getTime() === new Date(year, month, value).getTime()}
>
{value || ''}
</button>
{:else}
<div class="cell"></div>
{/if}
{/each}
</div>
</div>
Expand All @@ -74,7 +78,7 @@
}
.disabled {
@apply cursor-not-allowed bg-interactive text-disabled opacity-50;
@apply cursor-not-allowed bg-interactive/50 text-disabled;
}
.highlight {
Expand Down
17 changes: 12 additions & 5 deletions src/lib/holocene/date-picker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createEventDispatcher } from 'svelte';
import { clickoutside } from '$lib/holocene/outside-click';
import { translate } from '$lib/i18n/translate';
import { getMonthName } from '$lib/utilities/calendar';
import Calender from './calendar.svelte';
Expand Down Expand Up @@ -70,6 +71,9 @@
showDatePicker = false;
dispatch('datechange', d.detail);
};
const previousMonth = translate('date-picker.previous-month');
const nextMonth = translate('date-picker.next-month');
</script>

<div class="relative" use:clickoutside={() => (showDatePicker = false)}>
Expand All @@ -93,18 +97,21 @@
>
<div class="mx-3 my-2 flex items-center justify-around">
<div class="flex items-center justify-center">
<button type="button" on:click={prev}
><Icon name="chevron-left" /></button
<button type="button" on:click={prev} title={previousMonth}>
<span class="sr-only">{previousMonth}</span>
<Icon name="chevron-left" /></button
>
</div>
<div class="flex items-center justify-center">
{getMonthName(month)?.label ?? ''}
{year}
</div>
<div class="flex items-center justify-center">
<button type="button" on:click={next}
><Icon name="chevron-right" /></button
>
<span class="sr-only">Next Month</span>
<button type="button" on:click={next} title={nextMonth}>
<span class="sr-only">{nextMonth}</span>
<Icon name="chevron-right" />
</button>
</div>
</div>
<Calender
Expand Down
6 changes: 6 additions & 0 deletions src/lib/i18n/locales/en/date-picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const Namespace = 'date-picker' as const;

export const Strings = {
'next-month': 'Next Month',
'previous-month': 'Previous Month',
} as const;
2 changes: 2 additions & 0 deletions src/lib/i18n/locales/en/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Batch from './batch';
import * as Common from './common';
import * as DataEncoder from './data-encoder';
import * as DatePicker from './date-picker';
import * as Events from './events';
import * as Namespaces from './namespaces';
import * as Schedules from './schedules';
Expand All @@ -13,6 +14,7 @@ export const EN = 'en' as const;
export const English = {
[Batch.Namespace]: Batch.Strings,
[Common.Namespace]: Common.Strings,
[DatePicker.Namespace]: DatePicker.Strings,
[Workflows.Namespace]: Workflows.Strings,
[TypedErrors.Namespace]: TypedErrors.Strings,
[Events.Namespace]: Events.Strings,
Expand Down

0 comments on commit 2b8b941

Please sign in to comment.