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

[DateTimePicker] Ensure toolbar viewType is correctly updated #7942

Merged
merged 2 commits into from
Feb 20, 2023
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 @@ -11,6 +11,7 @@ import {
DateTimePickerToolbarClasses,
getDateTimePickerToolbarUtilityClass,
} from './dateTimePickerToolbarClasses';
import { resolveViewTypeFromView } from './shared';

export interface DateTimePickerToolbarProps<TDate> extends BaseToolbarProps<TDate, TDate | null> {
classes?: Partial<DateTimePickerToolbarClasses>;
Expand Down Expand Up @@ -122,6 +123,7 @@ export function DateTimePickerToolbar<TDate extends unknown>(
isMobileKeyboardViewOpen={isMobileKeyboardViewOpen}
toggleMobileKeyboardView={toggleMobileKeyboardView}
className={classes.root}
viewType={resolveViewTypeFromView(openView)}
{...other}
isLandscape={false}
ownerState={ownerState}
Expand Down
13 changes: 12 additions & 1 deletion packages/x-date-pickers/src/DateTimePicker/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DateTimeValidationError } from '../internals/hooks/validation/useDateTi
import { ValidationProps } from '../internals/hooks/validation/useValidation';
import { BasePickerProps } from '../internals/models/props/basePickerProps';
import { ExportedDateInputProps } from '../internals/components/PureDateInput';
import { CalendarOrClockPickerView } from '../internals/models';
import { CalendarOrClockPickerView, ViewType } from '../internals/models';
import { PickerStateValueManager } from '../internals/hooks/usePickerState';
import { parsePickerInputValue, parseNonNullablePickerDate } from '../internals/utils/date-utils';
import { BaseToolbarProps } from '../internals/models/props/baseToolbarProps';
Expand Down Expand Up @@ -146,3 +146,14 @@ export const dateTimePickerValueManager: PickerStateValueManager<any, any, any>
parseInput: parsePickerInputValue,
areValuesEqual: (utils, a, b) => utils.isEqual(a, b),
};

export const resolveViewTypeFromView = (view: CalendarOrClockPickerView): ViewType => {
switch (view) {
case 'year':
case 'month':
case 'day':
return 'calendar';
default:
return 'clock';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
pickersToolbarClasses,
PickersToolbarClasses,
} from './pickersToolbarClasses';
import { ViewType } from '../models';

export interface PickersToolbarProps<TDate, TValue>
extends Pick<
BaseToolbarProps<TDate, TValue>,
'getMobileKeyboardInputViewButtonText' | 'isMobileKeyboardViewOpen' | 'toggleMobileKeyboardView'
> {
className?: string;
viewType?: 'calendar' | 'clock';
viewType?: ViewType;
isLandscape: boolean;
landscapeDirection?: 'row' | 'column';
toolbarTitle: React.ReactNode;
Expand Down Expand Up @@ -83,7 +84,7 @@ const PickersToolbarPenIconButton = styled(IconButton, {
ownerState: PickersToolbarProps<any, any>;
}>({});

const getViewTypeIcon = (viewType: 'calendar' | 'clock') =>
const getViewTypeIcon = (viewType: ViewType) =>
viewType === 'clock' ? <Clock color="inherit" /> : <Calendar color="inherit" />;

type PickersToolbarComponent = (<TDate, TValue>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { CalendarOrClockPickerView } from '../views';
import { CalendarOrClockPickerView, ViewType } from '../views';
import type { PickerOnChangeFn } from '../../hooks/useViews';
import type { ExportedCalendarPickerProps } from '../../../CalendarPicker/CalendarPicker';
import type { ExportedClockPickerProps } from '../../../ClockPicker/ClockPicker';
Expand All @@ -15,12 +15,12 @@ export interface BaseToolbarProps<TDate, TValue>
* Text for aria label of the button switching between input and interactive view.
* @deprecated Use the translation key `inputModeToggleButtonAriaLabel` instead, see https://mui.com/x/react-date-pickers/localization
* @param {boolean} isKeyboardInputOpen Indicates if the interface is the keyboard input.
* @param {'calendar' | 'clock' } viewType Indicates if the interface is about a date or a time.
* @param {ViewType} viewType Indicates if the interface is about a date or a time.
* @returns {string} The arial label
*/
getMobileKeyboardInputViewButtonText?: (
isKeyboardInputOpen: boolean,
viewType: 'calendar' | 'clock',
viewType: ViewType,
) => string;
isLandscape: boolean;
onChange: PickerOnChangeFn<TDate>;
Expand Down
2 changes: 2 additions & 0 deletions packages/x-date-pickers/src/internals/models/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export type CalendarPickerView = 'year' | 'day' | 'month';
export type ClockPickerView = 'hours' | 'minutes' | 'seconds';

export type CalendarOrClockPickerView = CalendarPickerView | ClockPickerView;

export type ViewType = 'calendar' | 'clock';
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/locales/csCZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const csCZPickers: PickersLocaleText<any> = {
view === 'year'
? 'roční zobrazení otevřeno, přepněte do zobrazení kalendáře'
: 'zobrazení kalendáře otevřeno, přepněte do zobrazení roku',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `Zobrazení pro zadávání textu je otevřené, přepněte do zobrazení ${pickerViews[viewType]}`
: `Zobrazení ${pickerViews[viewType]} je otevřené, přepněte do zobrazení textového pole`,
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/deDE.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

// maps ClockPickerView to its translation
const clockViews = {
Expand All @@ -15,19 +14,19 @@ const pickerViews = {
clock: 'Uhransicht',
};

const deDEPickers: Partial<PickersLocaleText<any>> = {
const deDEPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'Letzter Monat',
nextMonth: 'Nächster Monat',

// View navigation
openPreviousView: 'Letzte Ansicht öffnen',
openNextView: 'Nächste Ansicht öffnen',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'Jahresansicht ist geöffnet, zur Kalenderansicht wechseln'
: 'Kalenderansicht ist geöffnet, zur Jahresansicht wechseln',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `Texteingabeansicht ist geöffnet, zur ${pickerViews[viewType]} wechseln`
: `${pickerViews[viewType]} ist geöffnet, zur Texteingabeansicht wechseln`,
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers/src/locales/enUS.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

// This object is not Partial<PickersLocaleText> because it is the default values

Expand All @@ -12,11 +11,11 @@ const enUSPickers: PickersLocaleText<any> = {
// View navigation
openPreviousView: 'open previous view',
openNextView: 'open next view',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'year view is open, switch to calendar view'
: 'calendar view is open, switch to year view',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `text input view is open, go to ${viewType} view`
: `${viewType} view is open, go to text input view`,
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/esES.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const views = {
hours: 'las horas',
minutes: 'los minutos',
seconds: 'los segundos',
};

const esESPickers: Partial<PickersLocaleText<any>> = {
const esESPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'Último mes',
nextMonth: 'Próximo mes',

// View navigation
openPreviousView: 'abrir la última vista',
openNextView: 'abrir la siguiente vista',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'la vista del año está abierta, cambie a la vista de calendario'
: 'la vista de calendario está abierta, cambie a la vista del año',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `la vista de entrada de texto está abierta, ir a la vista ${viewType}`
: `la vista ${viewType} está abierta, ir a la vista de entrada de texto`,
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/faIR.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const faIRPickers: Partial<PickersLocaleText<any>> = {
const faIRPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'ماه گذشته',
nextMonth: 'ماه آینده',

// View navigation
openPreviousView: 'نمای قبلی',
openNextView: 'نمای بعدی',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'نمای سال باز است، رفتن به نمای تقویم'
: 'نمای تقویم باز است، رفتن به نمای سال',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `نمای ورودی متن باز است، رفتن به نمای ${viewType}`
: `نمای ${viewType} باز است، رفتن به نمای ورودی متن`,
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/fiFI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const views = {
hours: 'tunnit',
Expand All @@ -13,19 +12,19 @@ const viewTranslation = {
clock: 'kello',
};

const fiFIPickers: Partial<PickersLocaleText<any>> = {
const fiFIPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'Edellinen kuukausi',
nextMonth: 'Seuraava kuukausi',

// View navigation
openPreviousView: 'avaa edellinen kuukausi',
openNextView: 'avaa seuraava kuukausi',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'vuosinäkymä on auki, vaihda kalenterinäkymään'
: 'kalenterinäkymä on auki, vaihda vuosinäkymään',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `tekstikenttä on auki, mene ${viewTranslation[viewType]}näkymään`
: `${viewTranslation[viewType]}näkymä on auki, mene tekstikenttään`,
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers/src/locales/frFR.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const views = {
hours: 'heures',
Expand All @@ -21,11 +20,11 @@ const frFRPickers: Partial<PickersLocaleText<any>> = {
// View navigation
openPreviousView: 'Ouvrir la vue précédente',
openNextView: 'Ouvrir la vue suivante',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'La vue année est ouverte, ouvrir la vue calendrier'
: 'La vue calendrier est ouverte, ouvrir la vue année',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `passer du champ text au ${viewTranslation[viewType]}`
: `passer du ${viewTranslation[viewType]} au champ text`,
Expand Down
10 changes: 3 additions & 7 deletions packages/x-date-pickers/src/locales/isIS.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const isISPickers: Partial<PickersLocaleText<any>> = {
const isISPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'Fyrri mánuður',
nextMonth: 'Næsti mánuður',

// View navigation
openPreviousView: 'opna fyrri skoðun',
openNextView: 'opna næstu skoðun',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'ársskoðun er opin, skipta yfir í dagatalsskoðun'
: 'dagatalsskoðun er opin, skipta yfir í ársskoðun',
inputModeToggleButtonAriaLabel: (
isKeyboardInputOpen: boolean,
viewType: 'calendar' | 'clock',
) => {
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) => {
const viewTypeTranslated = viewType === 'calendar' ? 'dagatals' : 'klukku';
return isKeyboardInputOpen
? `textainnsláttur er opinn, fara í ${viewTypeTranslated}skoðun`
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/itIT.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const views = {
hours: 'le ore',
minutes: 'i minuti',
seconds: 'i secondi',
};

const itITPickers: Partial<PickersLocaleText<any>> = {
const itITPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: 'Mese precedente',
nextMonth: 'Mese successivo',

// View navigation
openPreviousView: 'apri la vista precedente',
openNextView: 'apri la vista successiva',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? "la vista dell'anno è aperta, passare alla vista del calendario"
: "la vista dell'calendario è aperta, passare alla vista dell'anno",
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `la vista del campo di testo è aperta, passare alla vista ${viewType}`
: `la vista aperta è: ${viewType}, vai alla vista del campo di testo`,
Expand Down
7 changes: 3 additions & 4 deletions packages/x-date-pickers/src/locales/jaJP.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

// maps ClockPickerView to its translation
const clockViews = {
Expand All @@ -15,19 +14,19 @@ const pickerViews = {
clock: '時計表示',
};

const jaJPPickers: Partial<PickersLocaleText<any>> = {
const jaJPPickers: PickersLocaleText<any> = {
// Calendar navigation
previousMonth: '先月',
nextMonth: '来月',

// View navigation
openPreviousView: '前の表示を開く',
openNextView: '次の表示を開く',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? '年選択表示からカレンダー表示に切り替える'
: 'カレンダー表示から年選択表示に切り替える',
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') =>
inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) =>
isKeyboardInputOpen
? `テキスト入力表示から${pickerViews[viewType]}に切り替える`
: `${pickerViews[viewType]}からテキスト入力表示に切り替える`,
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers/src/locales/nbNO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const nbNOPickers: Partial<PickersLocaleText<any>> = {
// Calendar navigation
Expand All @@ -10,11 +9,11 @@ const nbNOPickers: Partial<PickersLocaleText<any>> = {
// View navigation
openPreviousView: 'åpne forrige visning',
openNextView: 'åpne neste visning',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'årsvisning er åpen, bytt til kalendervisning'
: 'kalendervisning er åpen, bytt til årsvisning',
// inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') => isKeyboardInputOpen ? `text input view is open, go to ${viewType} view` : `${viewType} view is open, go to text input view`,
// inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) => isKeyboardInputOpen ? `text input view is open, go to ${viewType} view` : `${viewType} view is open, go to text input view`,

// DateRange placeholders
start: 'Start',
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers/src/locales/nlNL.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PickersLocaleText } from './utils/pickersLocaleTextApi';
import { getPickersLocalization } from './utils/getPickersLocalization';
import { CalendarPickerView } from '../internals/models';

const nlNLPickers: Partial<PickersLocaleText<any>> = {
// Calendar navigation
Expand All @@ -10,11 +9,11 @@ const nlNLPickers: Partial<PickersLocaleText<any>> = {
// View navigation
openPreviousView: 'open vorige view',
openNextView: 'open volgende view',
calendarViewSwitchingButtonAriaLabel: (view: CalendarPickerView) =>
calendarViewSwitchingButtonAriaLabel: (view) =>
view === 'year'
? 'jaarweergave is geopend, schakel over naar kalenderweergave'
: 'kalenderweergave is geopend, switch naar jaarweergave',
// inputModeToggleButtonAriaLabel: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') => isKeyboardInputOpen ? `text input view is open, go to ${viewType} view` : `${viewType} view is open, go to text input view`,
// inputModeToggleButtonAriaLabel: (isKeyboardInputOpen, viewType) => isKeyboardInputOpen ? `text input view is open, go to ${viewType} view` : `${viewType} view is open, go to text input view`,

// DateRange placeholders
start: 'Start',
Expand Down
Loading