@@ -14,6 +14,10 @@ export interface SegmentedLabeledOption {
1414 disabled ?: boolean ;
1515 label : React . ReactNode ;
1616 value : SegmentedRawOption ;
17+ /**
18+ * html `title` property for label
19+ */
20+ title ?: string ;
1721}
1822
1923type SegmentedOptions = ( SegmentedRawOption | SegmentedLabeledOption ) [ ] ;
@@ -33,13 +37,31 @@ export interface SegmentedProps extends React.HTMLProps<HTMLDivElement> {
3337 motionName ?: string ;
3438}
3539
40+ function getValidTitle ( option : SegmentedLabeledOption ) {
41+ if ( typeof option . title !== 'undefined' ) {
42+ return option . title ;
43+ }
44+
45+ // read `label` when title is `undefined`
46+ if ( typeof option . label !== 'object' ) {
47+ return option . label ?. toString ( ) ;
48+ }
49+ }
50+
3651function normalizeOptions ( options : SegmentedOptions ) : SegmentedLabeledOption [ ] {
3752 return options . map ( ( option ) => {
38- if ( typeof option === 'object' ) {
39- return option || { } ;
53+ if ( typeof option === 'object' && option !== null ) {
54+ const validTitle = getValidTitle ( option ) ;
55+
56+ return {
57+ ...option ,
58+ title : validTitle ,
59+ } ;
4060 }
61+
4162 return {
4263 label : option ?. toString ( ) ,
64+ title : option ?. toString ( ) ,
4365 value : option ,
4466 } ;
4567 } ) ;
@@ -56,12 +78,22 @@ const InternalSegmentedOption: React.FC<{
5678 disabled ?: boolean ;
5779 checked : boolean ;
5880 label : React . ReactNode ;
81+ title ?: string ;
5982 value : SegmentedRawOption ;
6083 onChange : (
6184 e : React . ChangeEvent < HTMLInputElement > ,
6285 value : SegmentedRawOption ,
6386 ) => void ;
64- } > = ( { prefixCls, className, disabled, checked, label, value, onChange } ) => {
87+ } > = ( {
88+ prefixCls,
89+ className,
90+ disabled,
91+ checked,
92+ label,
93+ title,
94+ value,
95+ onChange,
96+ } ) => {
6597 const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
6698 if ( disabled ) {
6799 return ;
@@ -83,7 +115,9 @@ const InternalSegmentedOption: React.FC<{
83115 checked = { checked }
84116 onChange = { handleChange }
85117 />
86- < div className = { `${ prefixCls } -item-label` } > { label } </ div >
118+ < div className = { `${ prefixCls } -item-label` } title = { title } >
119+ { label }
120+ </ div >
87121 </ label >
88122 ) ;
89123} ;
0 commit comments