@@ -5,6 +5,7 @@ import type { FieldSection, MuiPickersAdapter } from '../../../models';
55import type { UseFieldDOMGetters , UseFieldInternalProps } from './useField.types' ;
66import { usePickerAdapter , usePickerTranslations } from '../../../hooks' ;
77import { syncSelectionToDOM } from './syncSelectionToDOM' ;
8+ import { getLocalizedDigits , removeLocalizedDigits } from './useField.utils' ;
89import type { UseFieldCharacterEditingReturnValue } from './useFieldCharacterEditing' ;
910import type { FieldRangeSection , PickerAnyManager } from '../../models' ;
1011import type { PickersSectionElement } from '../../../PickersSectionList' ;
@@ -19,6 +20,7 @@ export function useFieldSectionContentProps(
1920) : UseFieldSectionContentPropsReturnValue {
2021 const adapter = usePickerAdapter ( ) ;
2122 const translations = usePickerTranslations ( ) ;
23+ const localizedDigits = React . useMemo ( ( ) => getLocalizedDigits ( adapter ) , [ adapter ] ) ;
2224
2325 const {
2426 focused,
@@ -173,11 +175,11 @@ export function useFieldSectionContentProps(
173175
174176 // Aria attributes
175177 'aria-readonly' : readOnly ,
176- 'aria-valuenow' : getSectionValueNow ( section , adapter ) ,
178+ 'aria-valuenow' : getSectionValueNow ( section , adapter , localizedDigits ) ,
177179 'aria-valuemin' : sectionBoundaries . minimum ,
178180 'aria-valuemax' : sectionBoundaries . maximum ,
179181 'aria-valuetext' : section . value
180- ? getSectionValueText ( section , adapter )
182+ ? getSectionValueText ( section , adapter , localizedDigits )
181183 : translations . empty ,
182184 'aria-label' : translations [ section . type ] ,
183185 'aria-disabled' : disabled ,
@@ -204,6 +206,7 @@ export function useFieldSectionContentProps(
204206 isEditable ,
205207 translations ,
206208 adapter ,
209+ localizedDigits ,
207210 handleInput ,
208211 handlePaste ,
209212 handleMouseUp ,
@@ -232,14 +235,18 @@ type UseFieldSectionContentPropsReturnValue = (
232235function getSectionValueText (
233236 section : FieldSection ,
234237 adapter : MuiPickersAdapter ,
238+ localizedDigits : string [ ] ,
235239) : string | undefined {
236240 if ( ! section . value ) {
237241 return undefined ;
238242 }
239243 switch ( section . type ) {
240244 case 'month' : {
241245 if ( section . contentType === 'digit' ) {
242- const dateWithMonth = adapter . setMonth ( adapter . date ( ) , Number ( section . value ) - 1 ) ;
246+ const dateWithMonth = adapter . setMonth (
247+ adapter . date ( ) ,
248+ Number ( removeLocalizedDigits ( section . value , localizedDigits ) ) - 1 ,
249+ ) ;
243250 return adapter . isValid ( dateWithMonth ) ? adapter . format ( dateWithMonth , 'month' ) : '' ;
244251 }
245252 const parsedDate = adapter . parse ( section . value , section . format ) ;
@@ -251,7 +258,7 @@ function getSectionValueText(
251258 if ( section . contentType === 'digit' ) {
252259 const dateWithDay = adapter . setDate (
253260 adapter . startOfYear ( adapter . date ( ) ) ,
254- Number ( section . value ) ,
261+ Number ( removeLocalizedDigits ( section . value , localizedDigits ) ) ,
255262 ) ;
256263 // Announce a cardinal day (e.g. "2"), not a locale ordinal (e.g. French "2ème").
257264 // See https://github.com/mui/mui-x/issues/22915.
@@ -266,17 +273,22 @@ function getSectionValueText(
266273 }
267274}
268275
269- function getSectionValueNow ( section : FieldSection , adapter : MuiPickersAdapter ) : number | undefined {
276+ function getSectionValueNow (
277+ section : FieldSection ,
278+ adapter : MuiPickersAdapter ,
279+ localizedDigits : string [ ] ,
280+ ) : number | undefined {
270281 if ( ! section . value ) {
271282 return undefined ;
272283 }
284+ const nonLocalizedValue = removeLocalizedDigits ( section . value , localizedDigits ) ;
273285 switch ( section . type ) {
274286 case 'weekDay' : {
275287 if ( section . contentType === 'letter' ) {
276288 // TODO: improve by resolving the week day number from a letter week day
277289 return undefined ;
278290 }
279- return Number ( section . value ) ;
291+ return Number ( nonLocalizedValue ) ;
280292 }
281293 case 'meridiem' : {
282294 const parsedDate = adapter . parse (
@@ -290,16 +302,16 @@ function getSectionValueNow(section: FieldSection, adapter: MuiPickersAdapter):
290302 }
291303 case 'day' :
292304 return section . contentType === 'digit-with-letter'
293- ? parseInt ( section . value , 10 )
294- : Number ( section . value ) ;
305+ ? parseInt ( nonLocalizedValue , 10 )
306+ : Number ( nonLocalizedValue ) ;
295307 case 'month' : {
296308 if ( section . contentType === 'digit' ) {
297- return Number ( section . value ) ;
309+ return Number ( nonLocalizedValue ) ;
298310 }
299311 const parsedDate = adapter . parse ( section . value , section . format ) ;
300312 return parsedDate ? adapter . getMonth ( parsedDate ) + 1 : undefined ;
301313 }
302314 default :
303- return section . contentType !== 'letter' ? Number ( section . value ) : undefined ;
315+ return section . contentType !== 'letter' ? Number ( nonLocalizedValue ) : undefined ;
304316 }
305317}
0 commit comments