@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
import { range } from "./range" ;
3
3
import { compileDateString , parseDateString } from "./date-string" ;
4
4
import { Option , Options } from "./types" ;
5
+ import { useUtils } from "./LocalizationProvider/useUtils" ;
5
6
6
7
const DEFAULT_MIN_YEAR = 1960 ;
7
8
const DEFAULT_MAX_YEAR = new Date ( ) . getFullYear ( ) ;
@@ -17,9 +18,6 @@ function compileOption(value: string): Option {
17
18
return { value, label : value } ; // TODO: Be customizable for localization
18
19
}
19
20
20
- const monthOptions : Options = range ( 1 , 12 ) . map ( ( i ) =>
21
- compileOption ( convertToSelectValue ( i ) )
22
- ) ;
23
21
const dayOptions : Options = range ( 1 , 31 ) . map ( ( i ) =>
24
22
compileOption ( convertToSelectValue ( i ) )
25
23
) ;
@@ -169,6 +167,8 @@ export const useDateSelect = (
169
167
}
170
168
} , [ setDate , value ] ) ;
171
169
170
+ const utils = useUtils ( ) ;
171
+
172
172
const yearOptions = useMemo ( ( ) => {
173
173
const minYear = opts . minYear != null ? opts . minYear : DEFAULT_MIN_YEAR ;
174
174
const maxYear = opts . maxYear != null ? opts . maxYear : DEFAULT_MAX_YEAR ;
@@ -182,6 +182,15 @@ export const useDateSelect = (
182
182
return raw ;
183
183
} , [ opts . minYear , opts . maxYear , state . yearValue ] ) ;
184
184
185
+ const monthOptions : Options = useMemo ( ( ) => {
186
+ return range ( 1 , 12 ) . map ( ( i ) => {
187
+ const label = utils
188
+ ? utils . format ( new Date ( 1960 , i - 1 , 1 ) , "monthShort" )
189
+ : convertToSelectValue ( i ) ;
190
+ return { value : convertToSelectValue ( i ) , label } ;
191
+ } ) ;
192
+ } , [ utils ] ) ;
193
+
185
194
return {
186
195
yearValue : state . yearValue ,
187
196
monthValue : state . monthValue ,
0 commit comments