Skip to content

Commit

Permalink
[pickers] Fix time related aria labels to depend on ampm flag value (
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored Feb 14, 2025
1 parent 0d24408 commit 6e19f24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
7 changes: 1 addition & 6 deletions packages/x-date-pickers/src/TimeClock/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,7 @@ export function Clock(inProps: ClockProps) {
aria-activedescendant={selectedId}
aria-label={translations.clockLabelText(
type,
value == null
? null
: utils.format(
value,
utils.is12HourCycleInCurrentLocale() ? 'fullTime12h' : 'fullTime24h',
),
value == null ? null : utils.format(value, ampm ? 'fullTime12h' : 'fullTime24h'),
)}
ref={listboxRef}
role="listbox"
Expand Down
12 changes: 5 additions & 7 deletions packages/x-date-pickers/src/managers/useTimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PickerValue } from '../internals/models';
export function useTimeManager<TEnableAccessibleFieldDOMStructure extends boolean = true>(
parameters: UseTimeManagerParameters<TEnableAccessibleFieldDOMStructure> = {},
): UseTimeManagerReturnValue<TEnableAccessibleFieldDOMStructure> {
const { enableAccessibleFieldDOMStructure = true as TEnableAccessibleFieldDOMStructure } =
const { enableAccessibleFieldDOMStructure = true as TEnableAccessibleFieldDOMStructure, ampm } =
parameters;

return React.useMemo(
Expand All @@ -36,15 +36,12 @@ export function useTimeManager<TEnableAccessibleFieldDOMStructure extends boolea
}),
internal_getOpenPickerButtonAriaLabel: ({ value, utils, localeText }) => {
const formattedValue = utils.isValid(value)
? utils.format(
value,
utils.is12HourCycleInCurrentLocale() ? 'fullTime12h' : 'fullTime24h',
)
? utils.format(value, ampm ? 'fullTime12h' : 'fullTime24h')
: null;
return localeText.openTimePickerDialogue(formattedValue);
},
}),
[enableAccessibleFieldDOMStructure],
[ampm, enableAccessibleFieldDOMStructure],
);
}

Expand All @@ -66,7 +63,8 @@ export function getTimeFieldInternalPropsDefaults(
};
}

export interface UseTimeManagerParameters<TEnableAccessibleFieldDOMStructure extends boolean> {
export interface UseTimeManagerParameters<TEnableAccessibleFieldDOMStructure extends boolean>
extends AmPmProps {
enableAccessibleFieldDOMStructure?: TEnableAccessibleFieldDOMStructure;
}

Expand Down

0 comments on commit 6e19f24

Please sign in to comment.