File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export function getSingleContent(cascaderContext: CascaderContextType): string {
2727 }
2828 const path = node && node [ 0 ] . getPath ( ) ;
2929 if ( path && path . length ) {
30- return showAllLevels ? path . map ( ( node : TreeNode ) => node . label ) . join ( ' / ' ) : path [ path . length - 1 ] . label ;
30+ return showAllLevels ? path . map ( ( node : TreeNode ) => node . label ) . join ( ' / ' ) : path . at ( - 1 ) . label ;
3131 }
3232 return value as string ;
3333}
@@ -120,10 +120,11 @@ export const getCascaderValue = (value: CascaderValue, valueType: TdCascaderProp
120120 if ( valueType === 'single' ) {
121121 return value ;
122122 }
123+ const val = value as Array < CascaderValue > ;
123124 if ( multiple ) {
124- return ( value as Array < CascaderValue > ) . map ( ( item : TreeNodeValue [ ] ) => item [ item . length - 1 ] ) ;
125+ return val . map ( ( item : TreeNodeValue [ ] ) => item . at ( - 1 ) ) ;
125126 }
126- return value [ ( value as Array < CascaderValue > ) . length - 1 ] ;
127+ return val . at ( - 1 ) ;
127128} ;
128129
129130/**
@@ -144,6 +145,9 @@ export function isEmptyValues(value: unknown): boolean {
144145 * @returns boolean
145146 */
146147export function isValueInvalid ( value : CascaderValue , cascaderContext : CascaderContextType ) {
147- const { multiple, showAllLevels } = cascaderContext ;
148- return ( multiple && ! Array . isArray ( value ) ) || ( ! multiple && Array . isArray ( value ) && ! showAllLevels ) ;
148+ const { multiple, showAllLevels, valueType } = cascaderContext ;
149+ return (
150+ ( multiple && ! Array . isArray ( value ) )
151+ || ( ! multiple && Array . isArray ( value ) && valueType === 'single' && ! showAllLevels )
152+ ) ;
149153}
You can’t perform that action at this time.
0 commit comments