Skip to content

Commit

Permalink
[pickers] Adds RTL verification for the time pickers default views (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurbalduini authored Jun 20, 2024
1 parent 6a6c512 commit 5f49acf
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { useRtl } from '@mui/system/RtlProvider';
import { styled, useThemeProps } from '@mui/material/styles';
import useEventCallback from '@mui/utils/useEventCallback';
import composeClasses from '@mui/utils/composeClasses';
Expand Down Expand Up @@ -62,6 +63,7 @@ export const MultiSectionDigitalClock = React.forwardRef(function MultiSectionDi
TDate extends PickerValidDate,
>(inProps: MultiSectionDigitalClockProps<TDate>, ref: React.Ref<HTMLDivElement>) {
const utils = useUtils<TDate>();
const isRtl = useRtl();

const props = useThemeProps({
props: inProps,
Expand Down Expand Up @@ -389,6 +391,18 @@ export const MultiSectionDigitalClock = React.forwardRef(function MultiSectionDi
],
);

const viewsToRender = React.useMemo(() => {
if (!isRtl) {
return views;
}
const digitViews = views.filter((v) => v !== 'meridiem');
const result = digitViews.toReversed();
if (views.includes('meridiem')) {
result.push('meridiem');
}
return result;
}, [isRtl, views]);

const viewTimeOptions = React.useMemo(() => {
return views.reduce(
(result, currentView) => {
Expand All @@ -409,19 +423,19 @@ export const MultiSectionDigitalClock = React.forwardRef(function MultiSectionDi
role="group"
{...other}
>
{Object.entries(viewTimeOptions).map(([timeView, viewOptions]) => (
{viewsToRender.map((timeView) => (
<MultiSectionDigitalClockSection
key={timeView}
items={viewOptions.items}
onChange={viewOptions.onChange}
items={viewTimeOptions[timeView].items}
onChange={viewTimeOptions[timeView].onChange}
active={view === timeView}
autoFocus={autoFocus ?? focusedView === timeView}
disabled={disabled}
readOnly={readOnly}
slots={slots}
slotProps={slotProps}
skipDisabled={skipDisabled}
aria-label={localeText.selectViewText(timeView as TimeViewWithMeridiem)}
aria-label={localeText.selectViewText(timeView)}
/>
))}
</MultiSectionDigitalClockRoot>
Expand Down

0 comments on commit 5f49acf

Please sign in to comment.