@@ -3,20 +3,23 @@ import { useLayoutEffect } from '@rc-component/util';
33import * as React from 'react' ;
44import { usePanelContext } from '../../context' ;
55import useScrollTo from './useScrollTo' ;
6+ import type { Locale } from '../../../interface' ;
67
78const SCROLL_DELAY = 300 ;
89
910export type Unit < ValueType = number | string > = {
10- label : React . ReactText ;
11+ label : string | number ;
1112 value : ValueType ;
1213 disabled ?: boolean ;
1314} ;
1415
16+ type TimeUnitType = 'hour' | 'minute' | 'second' | 'millisecond' | 'meridiem' ;
17+
1518export interface TimeUnitColumnProps {
1619 units : Unit [ ] ;
1720 value : number | string ;
1821 optionalValue ?: number | string ;
19- type : 'hour' | 'minute' | 'second' | 'millisecond' | 'meridiem' ;
22+ type : TimeUnitType ;
2023 onChange : ( value : number | string ) => void ;
2124 onHover : ( value : number | string ) => void ;
2225 onDblClick ?: VoidFunction ;
@@ -28,6 +31,40 @@ function flattenUnits(units: Unit<string | number>[]) {
2831 return units . map ( ( { value, label, disabled } ) => [ value , label , disabled ] . join ( ',' ) ) . join ( ';' ) ;
2932}
3033
34+ function getListLabel ( type : TimeUnitType , locale : Locale ) {
35+ switch ( type ) {
36+ case 'hour' :
37+ return locale . hourSelect ;
38+ case 'minute' :
39+ return locale . minuteSelect ;
40+ case 'second' :
41+ return locale . secondSelect ;
42+ case 'millisecond' :
43+ return locale . millisecondSelect ;
44+ case 'meridiem' :
45+ return locale . meridiemSelect ;
46+ default :
47+ return '' ;
48+ }
49+ }
50+
51+ function getListItemLabel ( type : TimeUnitType , value : string | number , locale : Locale ) {
52+ switch ( type ) {
53+ case 'hour' :
54+ return `${ value } ${ locale . hours } ` ;
55+ case 'minute' :
56+ return `${ value } ${ locale . minutes } ` ;
57+ case 'second' :
58+ return `${ value } ${ locale . seconds } ` ;
59+ case 'millisecond' :
60+ return `${ value } ${ locale . milliseconds } ` ;
61+ case 'meridiem' :
62+ return value . toString ( ) ;
63+ default :
64+ return '' ;
65+ }
66+ }
67+
3168export default function TimeColumn < DateType extends object > ( props : TimeUnitColumnProps ) {
3269 const { units, value, optionalValue, type, onChange, onHover, onDblClick, changeOnScroll } =
3370 props ;
@@ -96,16 +133,28 @@ export default function TimeColumn<DateType extends object>(props: TimeUnitColum
96133 const columnPrefixCls = `${ panelPrefixCls } -column` ;
97134
98135 return (
99- < ul className = { columnPrefixCls } ref = { ulRef } data-type = { type } onScroll = { onInternalScroll } >
136+ < ul
137+ role = "listbox"
138+ aria-label = { getListLabel ( type , locale ) }
139+ className = { columnPrefixCls }
140+ ref = { ulRef }
141+ data-type = { type }
142+ onScroll = { onInternalScroll }
143+ >
100144 { units . map ( ( { label, value : unitValue , disabled } ) => {
101145 const inner = < div className = { `${ cellPrefixCls } -inner` } > { label } </ div > ;
146+ const isSelected = value === unitValue ;
102147
103148 return (
104149 < li
105150 key = { unitValue }
151+ aria-label = { getListItemLabel ( type , unitValue , locale ) }
152+ role = "option"
153+ aria-selected = { isSelected }
154+ aria-disabled = { disabled }
106155 style = { styles . item }
107156 className = { clsx ( cellPrefixCls , classNames . item , {
108- [ `${ cellPrefixCls } -selected` ] : value === unitValue ,
157+ [ `${ cellPrefixCls } -selected` ] : isSelected ,
109158 [ `${ cellPrefixCls } -disabled` ] : disabled ,
110159 } ) }
111160 onClick = { ( ) => {
0 commit comments