Skip to content

Commit

Permalink
[pickers] Correctly format MultiSectionDigitalClock number sections (
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored Dec 4, 2023
1 parent df4cd43 commit fd8baff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const MultiSectionDigitalClock = React.forwardRef(function MultiSectionDi
},
items: getTimeSectionOptions({
value: utils.getMinutes(valueOrReferenceDate),
utils,
isDisabled: (minutes) => disabled || isTimeDisabled(minutes, 'minutes'),
resolveLabel: (minutes) => utils.format(utils.setMinutes(now, minutes), 'minutes'),
timeStep: timeSteps.minutes,
Expand All @@ -324,6 +325,7 @@ export const MultiSectionDigitalClock = React.forwardRef(function MultiSectionDi
},
items: getTimeSectionOptions({
value: utils.getSeconds(valueOrReferenceDate),
utils,
isDisabled: (seconds) => disabled || isTimeDisabled(seconds, 'seconds'),
resolveLabel: (seconds) => utils.format(utils.setSeconds(now, seconds), 'seconds'),
timeStep: timeSteps.seconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,25 @@ export const getHourSectionOptions = <TDate>({
return result;
};

interface IGetTimeSectionOptions {
interface IGetTimeSectionOptions<TDate> {
value: number | null;
utils: MuiPickersAdapter<TDate>;
isDisabled: (value: number) => boolean;
timeStep: number;
resolveLabel: (value: number) => string;
hasValue?: boolean;
resolveAriaLabel: (value: string) => string;
}

export const getTimeSectionOptions = ({
export const getTimeSectionOptions = <TDate>({
value,
utils,
isDisabled,
timeStep,
resolveLabel,
resolveAriaLabel,
hasValue = true,
}: IGetTimeSectionOptions): MultiSectionDigitalClockOption<number>[] => {
}: IGetTimeSectionOptions<TDate>): MultiSectionDigitalClockOption<number>[] => {
const isSelected = (timeValue: number) => {
if (value === null) {
return false;
Expand All @@ -100,7 +102,7 @@ export const getTimeSectionOptions = ({
const timeValue = timeStep * index;
return {
value: timeValue,
label: resolveLabel(timeValue),
label: utils.formatNumber(resolveLabel(timeValue)),
isDisabled,
isSelected,
isFocused,
Expand Down

0 comments on commit fd8baff

Please sign in to comment.