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

[pickers] Stop using utils in locales #14505

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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DateField } from '../DateField';
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
import { renderDateViewCalendar } from '../dateViewRenderers';
import { resolveDateFormat } from '../internals/utils/date-utils';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

type DesktopDatePickerComponent = (<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -91,8 +92,12 @@ const DesktopDatePicker = React.forwardRef(function DesktopDatePicker<
props,
valueManager: singleItemValueManager,
valueType: 'date',
getOpenDialogAriaText:
props.localeText?.openDatePickerDialogue ?? translations.openDatePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullDate',
contextTranslation: translations.openDatePickerDialogue,
propsTranslation: props.localeText?.openDatePickerDialogue,
}),
validator: validateDate,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { DefaultizedProps } from '../internals/models/helpers';
import { UsePickerViewsProps } from '../internals/hooks/usePicker/usePickerViews';
import { isInternalTimeView } from '../internals/utils/time-utils';
import { isDatePickerView } from '../internals/utils/date-utils';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

const rendererInterceptor = function rendererInterceptor<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -226,8 +227,12 @@ const DesktopDateTimePicker = React.forwardRef(function DesktopDateTimePicker<
props,
valueManager: singleItemValueManager,
valueType: 'date-time',
getOpenDialogAriaText:
props.localeText?.openDatePickerDialogue ?? translations.openDatePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullDate',
contextTranslation: translations.openDatePickerDialogue,
propsTranslation: props.localeText?.openDatePickerDialogue,
}),
validator: validateDateTime,
rendererInterceptor,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TimeViewWithMeridiem } from '../internals/models';
import { resolveTimeFormat } from '../internals/utils/time-utils';
import { resolveTimeViewsResponse } from '../internals/utils/date-time-utils';
import { TimeView, PickerValidDate } from '../models';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

type DesktopTimePickerComponent = (<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -129,8 +130,12 @@ const DesktopTimePicker = React.forwardRef(function DesktopTimePicker<
props,
valueManager: singleItemValueManager,
valueType: 'time',
getOpenDialogAriaText:
props.localeText?.openTimePickerDialogue ?? translations.openTimePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullTime',
contextTranslation: translations.openTimePickerDialogue,
propsTranslation: props.localeText?.openTimePickerDialogue,
}),
validator: validateTime,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { extractValidationProps } from '../internals/utils/validation/extractVal
import { singleItemValueManager } from '../internals/utils/valueManagers';
import { renderDateViewCalendar } from '../dateViewRenderers';
import { resolveDateFormat } from '../internals/utils/date-utils';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

type MobileDatePickerComponent = (<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -88,8 +89,12 @@ const MobileDatePicker = React.forwardRef(function MobileDatePicker<
props,
valueManager: singleItemValueManager,
valueType: 'date',
getOpenDialogAriaText:
props.localeText?.openDatePickerDialogue ?? translations.openDatePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullDate',
contextTranslation: translations.openDatePickerDialogue,
propsTranslation: props.localeText?.openDatePickerDialogue,
}),
validator: validateDate,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { extractValidationProps } from '../internals/utils/validation/extractVal
import { renderDateViewCalendar } from '../dateViewRenderers';
import { renderTimeViewClock } from '../timeViewRenderers';
import { resolveDateTimeFormat } from '../internals/utils/date-time-utils';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

type MobileDateTimePickerComponent = (<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -103,8 +104,12 @@ const MobileDateTimePicker = React.forwardRef(function MobileDateTimePicker<
props,
valueManager: singleItemValueManager,
valueType: 'date-time',
getOpenDialogAriaText:
props.localeText?.openDatePickerDialogue ?? translations.openDatePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullDate',
contextTranslation: translations.openDatePickerDialogue,
propsTranslation: props.localeText?.openDatePickerDialogue,
}),
validator: validateDateTime,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useMobilePicker } from '../internals/hooks/useMobilePicker';
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
import { renderTimeViewClock } from '../timeViewRenderers';
import { resolveTimeFormat } from '../internals/utils/time-utils';
import { buildGetOpenDialogAriaText } from '../locales/utils/getPickersLocalization';

type MobileTimePickerComponent = (<
TDate extends PickerValidDate,
Expand Down Expand Up @@ -92,8 +93,12 @@ const MobileTimePicker = React.forwardRef(function MobileTimePicker<
props,
valueManager: singleItemValueManager,
valueType: 'time',
getOpenDialogAriaText:
props.localeText?.openTimePickerDialogue ?? translations.openTimePickerDialogue,
getOpenDialogAriaText: buildGetOpenDialogAriaText({
utils,
formatKey: 'fullTime',
contextTranslation: translations.openTimePickerDialogue,
propsTranslation: props.localeText?.openTimePickerDialogue,
}),
validator: validateTime,
});

Expand Down
7 changes: 6 additions & 1 deletion packages/x-date-pickers/src/TimeClock/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,12 @@ export function Clock<TDate extends PickerValidDate>(inProps: ClockProps<TDate>)
)}
<ClockWrapper
aria-activedescendant={selectedId}
aria-label={translations.clockLabelText(type, value, utils)}
aria-label={translations.clockLabelText(
type,
value,
utils,
value == null ? null : utils.format(value, 'fullTime'),
)}
ref={listboxRef}
role="listbox"
onKeyDown={handleKeyDown}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
UseDesktopPickerProps,
UseDesktopPickerSlotProps,
} from './useDesktopPicker.types';
import { useUtils } from '../useUtils';
import { usePicker } from '../usePicker';
import { LocalizationProvider } from '../../../LocalizationProvider';
import { PickersLayout } from '../../../PickersLayout';
Expand Down Expand Up @@ -67,7 +66,6 @@ export const useDesktopPicker = <
reduceAnimations,
} = props;

const utils = useUtils<TDate>();
const containerRef = React.useRef<HTMLDivElement>(null);
const fieldRef = React.useRef<FieldRef<FieldSection>>(null);

Expand Down Expand Up @@ -113,7 +111,7 @@ export const useDesktopPicker = <
additionalProps: {
disabled: disabled || readOnly,
onClick: open ? actions.onClose : actions.onOpen,
'aria-label': getOpenDialogAriaText(pickerFieldProps.value, utils),
'aria-label': getOpenDialogAriaText(pickerFieldProps.value),
edge: inputAdornmentProps.position,
},
ownerState: props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
} from '../../models/props/basePickerProps';
import { PickersPopperSlots, PickersPopperSlotProps } from '../../components/PickersPopper';
import { UsePickerParams, UsePickerProps } from '../usePicker';
import {
BaseSingleInputFieldProps,
FieldSection,
MuiPickersAdapter,
PickerValidDate,
} from '../../../models';
import { BaseSingleInputFieldProps, FieldSection, PickerValidDate } from '../../../models';
import {
ExportedPickersLayoutSlots,
ExportedPickersLayoutSlotProps,
Expand Down Expand Up @@ -151,5 +146,5 @@ export interface UseDesktopPickerParams<
'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor'
> {
props: TExternalProps;
getOpenDialogAriaText: (date: TDate | null, utils: MuiPickersAdapter<TDate>) => string;
getOpenDialogAriaText: (date: TDate | null) => string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from './useMobilePicker.types';
import { usePicker } from '../usePicker';
import { onSpaceOrEnter } from '../../utils/utils';
import { useUtils } from '../useUtils';
import { LocalizationProvider } from '../../../LocalizationProvider';
import { PickersLayout } from '../../../PickersLayout';
import { InferError } from '../useValidation';
Expand Down Expand Up @@ -63,7 +62,6 @@ export const useMobilePicker = <
localeText,
} = props;

const utils = useUtils<TDate>();
const fieldRef = React.useRef<FieldRef<FieldSection>>(null);

const labelId = useId();
Expand Down Expand Up @@ -128,7 +126,7 @@ export const useMobilePicker = <
// TODO: Move to `useSlotProps` when https://github.com/mui/material-ui/pull/35088 will be merged
fieldProps.inputProps = {
...fieldProps.inputProps,
'aria-label': getOpenDialogAriaText(pickerFieldProps.value, utils),
'aria-label': getOpenDialogAriaText(pickerFieldProps.value),
} as typeof fieldProps.inputProps;

const slotsForField = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import {
PickersModalDialogSlotProps,
} from '../../components/PickersModalDialog';
import { UsePickerParams, UsePickerProps } from '../usePicker';
import {
BaseSingleInputFieldProps,
FieldSection,
MuiPickersAdapter,
PickerValidDate,
} from '../../../models';
import { BaseSingleInputFieldProps, FieldSection, PickerValidDate } from '../../../models';
import {
ExportedPickersLayoutSlots,
ExportedPickersLayoutSlotProps,
Expand Down Expand Up @@ -112,5 +107,5 @@ export interface UseMobilePickerParams<
'valueManager' | 'valueType' | 'validator'
> {
props: TExternalProps;
getOpenDialogAriaText: (date: TDate | null, utils: MuiPickersAdapter<TDate>) => string;
getOpenDialogAriaText: (date: TDate | null) => string;
}
16 changes: 8 additions & 8 deletions packages/x-date-pickers/src/locales/beBY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const beBYPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Абраць каляндарны перыяд',

// Clock labels
clockLabelText: (view, time, adapter) =>
`Абярыце ${views[view]}. ${time === null ? 'Час не абраны' : `Абраны час ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, time, utils, formattedTime) =>
`Абярыце ${views[view]}. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Час не абраны' : `Абраны час ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
hoursClockNumberText: (hours) => `${hours} гадзін`,
minutesClockNumberText: (minutes) => `${minutes} хвілін`,
secondsClockNumberText: (seconds) => `${seconds} секунд`,
Expand All @@ -60,13 +60,13 @@ const beBYPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Абраць дату, абрана дата ${utils.format(value, 'fullDate')}`
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Абраць дату, абрана дата ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Абраць дату',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Абраць час, абрыны час ${utils.format(value, 'fullTime')}`
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Абраць час, абрыны час ${formattedTime ?? utils.format(value, 'fullTime')}`
: 'Абраць час',
// fieldClearLabel: 'Clear value',

Expand Down
16 changes: 8 additions & 8 deletions packages/x-date-pickers/src/locales/caES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const caESPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Seleccionar rang de dates',

// Clock labels
clockLabelText: (view, time, adapter) =>
`Selecciona ${views[view]}. ${time === null ? 'Hora no seleccionada' : `L'hora seleccionada és ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, time, utils, formattedTime) =>
`Selecciona ${views[view]}. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Hora no seleccionada' : `L'hora seleccionada és ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
hoursClockNumberText: (hours) => `${hours} hores`,
minutesClockNumberText: (minutes) => `${minutes} minuts`,
secondsClockNumberText: (seconds) => `${seconds} segons`,
Expand All @@ -59,13 +59,13 @@ const caESPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Tria la data, la data triada és ${utils.format(value, 'fullDate')}`
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Tria la data, la data triada és ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Tria la data',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Tria l'hora, l'hora triada és ${utils.format(value, 'fullTime')}`
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Tria l'hora, l'hora triada és ${formattedTime ?? utils.format(value, 'fullTime')}`
: "Tria l'hora",
fieldClearLabel: 'Netega el valor',

Expand Down
16 changes: 8 additions & 8 deletions packages/x-date-pickers/src/locales/csCZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const csCZPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Vyberete rozmezí dat',

// Clock labels
clockLabelText: (view, time, adapter) =>
`${timeViews[view] ?? view} vybrány. ${time === null ? 'Není vybrán čas' : `Vybraný čas je ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, time, utils, formattedTime) =>
`${timeViews[view] ?? view} vybrány. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Není vybrán čas' : `Vybraný čas je ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
hoursClockNumberText: (hours) => `${hours} hodin`,
minutesClockNumberText: (minutes) => `${minutes} minut`,
secondsClockNumberText: (seconds) => `${seconds} sekund`,
Expand All @@ -60,13 +60,13 @@ const csCZPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Vyberte datum, vybrané datum je ${utils.format(value, 'fullDate')}`
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Vyberte datum, vybrané datum je ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Vyberte datum',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Vyberte čas, vybraný čas je ${utils.format(value, 'fullTime')}`
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Vyberte čas, vybraný čas je ${formattedTime ?? utils.format(value, 'fullTime')}`
: 'Vyberte čas',
// fieldClearLabel: 'Clear value',

Expand Down
16 changes: 8 additions & 8 deletions packages/x-date-pickers/src/locales/daDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const daDKPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Vælg datointerval',

// Clock labels
clockLabelText: (view, time, adapter) =>
`Vælg ${timeViews[view] ?? view}. ${time === null ? 'Intet tidspunkt valgt' : `Valgte tidspunkt er ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, time, utils, formattedTime) =>
`Vælg ${timeViews[view] ?? view}. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Intet tidspunkt valgt' : `Valgte tidspunkt er ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
hoursClockNumberText: (hours) => `${hours} timer`,
minutesClockNumberText: (minutes) => `${minutes} minutter`,
secondsClockNumberText: (seconds) => `${seconds} sekunder`,
Expand All @@ -60,13 +60,13 @@ const daDKPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Vælg dato, valgte dato er ${utils.format(value, 'fullDate')}`
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Vælg dato, valgte dato er ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Vælg dato',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Vælg tidspunkt, valgte tidspunkt er ${utils.format(value, 'fullTime')}`
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Vælg tidspunkt, valgte tidspunkt er ${formattedTime ?? utils.format(value, 'fullTime')}`
: 'Vælg tidspunkt',
fieldClearLabel: 'ryd felt',

Expand Down
16 changes: 8 additions & 8 deletions packages/x-date-pickers/src/locales/deDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const deDEPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Datumsbereich auswählen',

// Clock labels
clockLabelText: (view, time, adapter) =>
`${timeViews[view] ?? view} auswählen. ${time === null ? 'Keine Uhrzeit ausgewählt' : `Gewählte Uhrzeit ist ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, time, utils, formattedTime) =>
`${timeViews[view] ?? view} auswählen. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Keine Uhrzeit ausgewählt' : `Gewählte Uhrzeit ist ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
hoursClockNumberText: (hours) => `${hours} ${timeViews.hours}`,
minutesClockNumberText: (minutes) => `${minutes} ${timeViews.minutes}`,
secondsClockNumberText: (seconds) => `${seconds} ${timeViews.seconds}`,
Expand All @@ -60,13 +60,13 @@ const deDEPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Datum auswählen, gewähltes Datum ist ${utils.format(value, 'fullDate')}`
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Datum auswählen, gewähltes Datum ist ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Datum auswählen',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Uhrzeit auswählen, gewählte Uhrzeit ist ${utils.format(value, 'fullTime')}`
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Uhrzeit auswählen, gewählte Uhrzeit ist ${formattedTime ?? utils.format(value, 'fullTime')}`
: 'Uhrzeit auswählen',
fieldClearLabel: 'Wert leeren',

Expand Down
Loading