Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10320,7 +10320,7 @@ Defaults to \`day\`.",
the component.",
"i18nTag": true,
"inlineType": {
"name": "CalendarProps.I18nStrings",
"name": "DatePickerProps.I18nStrings",
"properties": [
{
"name": "currentMonthAriaLabel",
Expand All @@ -10337,6 +10337,22 @@ the component.",
"optional": true,
"type": "string",
},
{
"inlineType": {
"name": "DatePickerProps.OpenCalendarAriaLabel",
"parameters": [
{
"name": "selectedDate",
"type": "string | null",
},
],
"returnType": "string",
"type": "function",
},
"name": "openCalendarAriaLabel",
"optional": true,
"type": "DatePickerProps.OpenCalendarAriaLabel",
},
{
"name": "previousMonthAriaLabel",
"optional": true,
Expand All @@ -10357,7 +10373,7 @@ the component.",
},
"name": "i18nStrings",
"optional": true,
"type": "CalendarProps.I18nStrings",
"type": "DatePickerProps.I18nStrings",
},
{
"deprecatedTag": "The usage of the \`id\` attribute is reserved for internal use cases. For testing and other use cases,
Expand Down Expand Up @@ -10440,6 +10456,7 @@ Supported values and formats are listed in the
"type": "string",
},
{
"deprecatedTag": "Use \`i18nStrings.openCalendarAriaLabel\` instead.",
"description": "Specifies a function that generates the \`aria-label\` for the 'open calendar' button. The \`selectedDate\` parameter is
a human-readable localised string representing the current value of the input.
(for example, \`\`selectedDate => 'Choose Date' + (selectedDate ? \`, selected date is \${selectedDate}\` : '')\`\`)",
Expand Down
66 changes: 66 additions & 0 deletions src/date-picker/__tests__/date-picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { render } from '@testing-library/react';

import DatePicker, { DatePickerProps } from '../../../lib/components/date-picker';
import FormField from '../../../lib/components/form-field';
import TestI18nProvider from '../../../lib/components/i18n/testing';
import { NonCancelableEventHandler } from '../../../lib/components/internal/events';
import createWrapper from '../../../lib/components/test-utils/dom';
import DatePickerWrapper from '../../../lib/components/test-utils/dom/date-picker';
Expand Down Expand Up @@ -422,3 +423,68 @@ describe('generates aria-label for the "Open calendar" button', () => {
expect(button).toHaveAttribute('aria-label', 'Choose Date');
});
});

describe('i18n', () => {
test('uses openCalendarAriaLabel from i18n provider when no date is selected', () => {
const { container } = render(
<TestI18nProvider
messages={{
'date-picker': {
'i18nStrings.openCalendarAriaLabel':
'{selectedDate, select, none {Choose calendar date} other {Choose calendar date, selected {selectedDate}}}',
},
}}
>
<DatePicker value="" locale="en-US" openCalendarAriaLabel={undefined} />
</TestI18nProvider>
);
const wrapper = createWrapper(container).findDatePicker()!;
expect(wrapper.findOpenCalendarButton().getElement()).toHaveAttribute('aria-label', 'Choose calendar date');
});

test('uses openCalendarAriaLabel from i18n provider when date is selected', () => {
const { container } = render(
<TestI18nProvider
messages={{
'date-picker': {
'i18nStrings.openCalendarAriaLabel':
'{selectedDate, select, none {Choose calendar date} other {Choose calendar date, selected {selectedDate}}}',
},
}}
>
<DatePicker value="2003-04-11" locale="en-US" openCalendarAriaLabel={undefined} />
</TestI18nProvider>
);
const wrapper = createWrapper(container).findDatePicker()!;
expect(wrapper.findOpenCalendarButton().getElement()).toHaveAttribute(
'aria-label',
'Choose calendar date, selected Friday, April 11, 2003'
);
});

test('uses openCalendarAriaLabel prop over i18n provider', () => {
const { container } = render(
<TestI18nProvider
messages={{
'date-picker': {
'i18nStrings.openCalendarAriaLabel':
'{selectedDate, select, none {Choose calendar date} other {Choose calendar date, selected {selectedDate}}}',
},
}}
>
<DatePicker
value="2003-04-11"
locale="en-US"
openCalendarAriaLabel={selectedDate =>
selectedDate ? `Custom label, selected ${selectedDate}` : 'Custom label'
}
/>
</TestI18nProvider>
);
const wrapper = createWrapper(container).findDatePicker()!;
expect(wrapper.findOpenCalendarButton().getElement()).toHaveAttribute(
'aria-label',
'Custom label, selected Friday, April 11, 2003'
);
});
});
20 changes: 13 additions & 7 deletions src/date-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { InternalButton } from '../button/internal';
import InternalCalendar from '../calendar/internal';
import { useFormFieldContext } from '../contexts/form-field.js';
import InternalDateInput from '../date-input/internal';
import { useInternalI18n } from '../i18n/context.js';
import { useLocale } from '../i18n/context.js';
import { InputProps } from '../input/interfaces';
import { getBaseProps } from '../internal/base-component';
Expand Down Expand Up @@ -73,6 +74,7 @@ const DatePicker = React.forwardRef(
});
checkControlled('DatePicker', 'value', value, 'onChange', onChange);

const i18n = useInternalI18n('date-picker');
const contextLocale = useLocale();
const normalizedLocale = normalizeLocale('DatePicker', locale || contextLocale);

Expand Down Expand Up @@ -123,13 +125,17 @@ const DatePicker = React.forwardRef(

const hasFullValue = isValidFullDate({ date: value, granularity });

const buttonAriaLabel =
openCalendarAriaLabel &&
openCalendarAriaLabel(
hasFullValue && parsedValue
? getSelectedDateLabel({ date: parsedValue, granularity, locale: normalizedLocale })
: null
);
const defaultOpenCalendarAriaLabel = i18n(
'i18nStrings.openCalendarAriaLabel',
i18nStrings?.openCalendarAriaLabel ?? openCalendarAriaLabel,
format => (selectedDate: string | null) => format({ selectedDate: selectedDate ?? 'none' })
);

const buttonAriaLabel = defaultOpenCalendarAriaLabel?.(
hasFullValue && parsedValue
? getSelectedDateLabel({ date: parsedValue, granularity, locale: normalizedLocale })
: null
);

const trigger = (
<div className={styles['date-picker-trigger']}>
Expand Down
10 changes: 9 additions & 1 deletion src/date-picker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DatePickerProps
* Specifies a function that generates the `aria-label` for the 'open calendar' button. The `selectedDate` parameter is
* a human-readable localised string representing the current value of the input.
* (for example, ``selectedDate => 'Choose Date' + (selectedDate ? `, selected date is ${selectedDate}` : '')``)
* @deprecated Use `i18nStrings.openCalendarAriaLabel` instead.
*/
openCalendarAriaLabel?: DatePickerProps.OpenCalendarAriaLabel;

Expand Down Expand Up @@ -130,7 +131,14 @@ export namespace DatePickerProps {
focus(): void;
}

export type I18nStrings = CalendarProps.I18nStrings;
export interface I18nStrings extends CalendarProps.I18nStrings {
/**
* Specifies a function that generates the `aria-label` for the 'open calendar' button. The `selectedDate` parameter is
* a human-readable localised string representing the current value of the input, or `null` when no date is selected.
* @i18n
*/
openCalendarAriaLabel?: OpenCalendarAriaLabel;
}

export type Granularity = DateGranularity;

Expand Down
11 changes: 11 additions & 0 deletions src/i18n/messages-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export interface I18nFormatArgTypes {
"copy-to-clipboard": {
"i18nStrings.copyButtonText": never;
}
"date-picker": {
"i18nStrings.openCalendarAriaLabel": {
"selectedDate": string;
}
}
"date-range-picker": {
"i18nStrings.relativeModeTitle": never;
"i18nStrings.absoluteModeTitle": never;
Expand Down Expand Up @@ -217,6 +222,12 @@ export interface I18nFormatArgTypes {
"drawer": {
"i18nStrings.loadingText": never;
}
"error-boundary": {
"i18nStrings.headerText": never;
"i18nStrings.descriptionText": never;
"i18nStrings.descriptionWithFeedbackText": never;
"i18nStrings.refreshActionText": never;
}
"file-token-group": {
"i18nStrings.limitShowFewer": never;
"i18nStrings.limitShowMore": never;
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "نسخ"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {اختر التاريخ} other {اختر التاريخ، التاريخ المحدد هو {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "الوضع النسبي",
"i18nStrings.absoluteModeTitle": "الوضع المُطلق",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "جار تحميل المحتوى"
},
"error-boundary": {
"i18nStrings.headerText": "خطأ غير متوقع، فشل عرض المحتوى",
"i18nStrings.descriptionText": "حدِّث الصفحة للمحاولة مرة أخرى.",
"i18nStrings.descriptionWithFeedbackText": "حدِّث الصفحة للمحاولة مرة أخرى. نحن نتتبع هذه المشكلة، ولكن يمكنك مشاركة <Feedback>المزيد من المعلومات هنا</Feedback>.",
"i18nStrings.refreshActionText": "تحديث الصفحة"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "إظهار عدد أقل من عوامل التصفية",
"i18nStrings.limitShowMore": "عرض المزيد من عوامل التصفية",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Kopieren"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Datum wählen} other {Datum wählen, ausgewähltes Datum ist {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Relativer Modus",
"i18nStrings.absoluteModeTitle": "Absoluter Modus",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Inhalte werden geladen"
},
"error-boundary": {
"i18nStrings.headerText": "Unerwarteter Fehler, Inhalt konnte nicht angezeigt werden",
"i18nStrings.descriptionText": "Aktualisieren Sie die Seite, um es erneut zu versuchen.",
"i18nStrings.descriptionWithFeedbackText": "Aktualisieren Sie die Seite, um es erneut zu versuchen. Wir verfolgen dieses Problem nach, Sie können aber <Feedback>hier zusätzliche Informationen mitteilen</Feedback>.",
"i18nStrings.refreshActionText": "Seite aktualisieren"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Weniger anzeigen",
"i18nStrings.limitShowMore": "Mehr anzeigen",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Copy"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Choose a date} other {Choose a date, the selected date is {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Relative mode",
"i18nStrings.absoluteModeTitle": "Absolute mode",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Loading content"
},
"error-boundary": {
"i18nStrings.headerText": "Unexpected error, content failed to show",
"i18nStrings.descriptionText": "Refresh to try again.",
"i18nStrings.descriptionWithFeedbackText": "Refresh to try again. We are tracking this issue, but you can share <Feedback>more information here</Feedback>.",
"i18nStrings.refreshActionText": "Refresh page"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Show fewer",
"i18nStrings.limitShowMore": "Show more",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Copy"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Choose date} other {Choose date, selected date is {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Relative mode",
"i18nStrings.absoluteModeTitle": "Absolute mode",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Loading content"
},
"error-boundary": {
"i18nStrings.headerText": "Unexpected error, content failed to show",
"i18nStrings.descriptionText": "Refresh to try again.",
"i18nStrings.descriptionWithFeedbackText": "Refresh to try again. We are tracking this issue, but you can share <Feedback>more information here</Feedback>.",
"i18nStrings.refreshActionText": "Refresh page"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Show fewer",
"i18nStrings.limitShowMore": "Show more",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Copiar"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Elegir fecha} other {Elegir fecha; la fecha seleccionada es {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Modo relativo",
"i18nStrings.absoluteModeTitle": "Modo absoluto",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Cargando contenido"
},
"error-boundary": {
"i18nStrings.headerText": "Error inesperado. No se pudo mostrar el contenido",
"i18nStrings.descriptionText": "Actualice para intentarlo de nuevo.",
"i18nStrings.descriptionWithFeedbackText": "Actualice para intentarlo de nuevo. Estamos siguiendo este problema, pero puede compartir <Feedback>más información aquí</Feedback>.",
"i18nStrings.refreshActionText": "Actualizar página"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Mostrar menos",
"i18nStrings.limitShowMore": "Mostrar más",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Copier"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Sélectionner la date} other {Sélectionnez la date, la date sélectionnée est le {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Mode relatif",
"i18nStrings.absoluteModeTitle": "Mode absolu",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Chargement du contenu en cours"
},
"error-boundary": {
"i18nStrings.headerText": "Erreur inattendue, le contenu n'a pas pu s'afficher",
"i18nStrings.descriptionText": "Actualisez pour réessayer.",
"i18nStrings.descriptionWithFeedbackText": "Actualisez pour réessayer. Nous suivons ce problème mais vous pouvez fournir <Feedback>plus d'informations ici</Feedback>.",
"i18nStrings.refreshActionText": "Actualiser la page"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Afficher moins",
"i18nStrings.limitShowMore": "Afficher plus",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.id.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Salin"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Pilih tanggal} other {Pilih tanggal, tanggal yang dipilih adalah {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Mode relatif",
"i18nStrings.absoluteModeTitle": "Mode absolut",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Memuat konten"
},
"error-boundary": {
"i18nStrings.headerText": "Kesalahan tak terduga, konten gagal ditampilkan",
"i18nStrings.descriptionText": "Refresh untuk mencoba lagi.",
"i18nStrings.descriptionWithFeedbackText": "Refresh untuk mencoba lagi. Kami sedang melacak masalah ini, tetapi Anda dapat membagikan <Feedback>informasi selengkapnya di sini</Feedback>.",
"i18nStrings.refreshActionText": "Segarkan halaman"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Tampilkan lebih sedikit",
"i18nStrings.limitShowMore": "Tampilkan selengkapnya",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/messages/all.it.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"copy-to-clipboard": {
"i18nStrings.copyButtonText": "Copia"
},
"date-picker": {
"i18nStrings.openCalendarAriaLabel": "{selectedDate, select, none {Scegli data} other {Scegli data, la data selezionata è {selectedDate}}}"
},
"date-range-picker": {
"i18nStrings.relativeModeTitle": "Modalità relativa",
"i18nStrings.absoluteModeTitle": "Modalità assoluta",
Expand Down Expand Up @@ -172,6 +175,12 @@
"drawer": {
"i18nStrings.loadingText": "Caricamento dei contenuti"
},
"error-boundary": {
"i18nStrings.headerText": "Errore imprevisto, impossibile visualizzare il contenuto",
"i18nStrings.descriptionText": "Aggiorna la pagina per riprovare.",
"i18nStrings.descriptionWithFeedbackText": "Aggiorna la pagina per riprovare. Stiamo monitorando il problema, ma puoi condividere <Feedback>maggiori informazioni qui</Feedback>.",
"i18nStrings.refreshActionText": "Aggiorna pagina"
},
"file-token-group": {
"i18nStrings.limitShowFewer": "Mostra meno",
"i18nStrings.limitShowMore": "Mostra altro",
Expand Down
Loading
Loading