Repository: ant-design/ant-design-mobile
Pull request #6258 (2023-07-18 08:42:00)

chore: side add type specification

github-actions[bot]: PR preview has been successfully built and deployed to https://antd-mobile-preview-pr-6258.surge.sh

Patch:
diff --git a/src/components/steps/steps.tsx b/src/components/steps/steps.tsx
index 8f85fe243..224c3de33 100644
--- a/src/components/steps/steps.tsx
+++ b/src/components/steps/steps.tsx
@@ -1,6 +1,6 @@
 import React, { FC } from 'react'
 import classNames from 'classnames'
-import { StepProps } from './step'
+import type { StepProps } from './step'
 import { mergeProps } from '../../utils/with-default-props'
 import { NativeProps, withNativeProps } from '../../utils/native-props'
 
@@ -53,7 +53,7 @@ export const Steps: FC<StepsProps> = p => {
         return React.cloneElement(child, {
           status,
           icon,
-        })
+        } as StepProps)
       })}
     </div>
   )
diff --git a/src/components/swipe-action/swipe-action.tsx b/src/components/swipe-action/swipe-action.tsx
index 75d39e225..dd912649e 100644
--- a/src/components/swipe-action/swipe-action.tsx
+++ b/src/components/swipe-action/swipe-action.tsx
@@ -19,9 +19,11 @@ import {
 
 const classPrefix = `adm-swipe-action`
 
+type SideType = 'left' | 'right'
+
 export type SwipeActionRef = {
   close: () => void
-  show: (side?: 'left' | 'right') => void
+  show: (side?: SideType) => void
 }
 
 type ActionColor =
@@ -47,7 +49,7 @@ export type SwipeActionProps = {
   closeOnAction?: boolean
   children: ReactNode
   stopPropagation?: PropagationEvent[]
-  onActionsReveal?: (side: 'left' | 'right') => void
+  onActionsReveal?: (side: SideType) => void
 } & NativeProps<'--background'>
 
 const defaultProps = {
@@ -157,7 +159,7 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>(
     }
 
     useImperativeHandle(ref, () => ({
-      show: (side: 'left' | 'right' = 'right') => {
+      show: (side: SideType = 'right') => {
         if (side === 'right') {
           api.start({
             x: -getRightWidth(),
diff --git a/src/components/text-area/text-area.tsx b/src/components/text-area/text-area.tsx
index dcc3e47df..b799f4001 100644
--- a/src/components/text-area/text-area.tsx
+++ b/src/components/text-area/text-area.tsx
@@ -135,13 +135,23 @@ export const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
       )
     }
 
+    let rows = props.rows
+    if (typeof autoSize === 'object') {
+      if (autoSize.maxRows && rows > autoSize.maxRows) {
+        rows = autoSize.maxRows
+      }
+      if (autoSize.minRows && rows < autoSize.minRows) {
+        rows = autoSize.minRows
+      }
+    }
+
     return withNativeProps(
       props,
       <div className={classPrefix}>
         <textarea
           ref={nativeTextAreaRef}
           className={`${classPrefix}-element`}
-          rows={props.rows}
+          rows={rows}
           value={value}
           placeholder={props.placeholder}
           onChange={e => {
@@ -180,7 +190,7 @@ export const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
             ref={hiddenTextAreaRef}
             className={`${classPrefix}-element ${classPrefix}-element-hidden`}
             value={value}
-            rows={props.rows}
+            rows={rows}
             aria-hidden
             readOnly
           />


Test patch:
diff --git a/src/components/text-area/tests/text-area.test.tsx b/src/components/text-area/tests/text-area.test.tsx
index 6f3d4dfc8..d5aba7ff6 100644
--- a/src/components/text-area/tests/text-area.test.tsx
+++ b/src/components/text-area/tests/text-area.test.tsx
@@ -130,4 +130,16 @@ describe('TextArea', () => {
     expect(textarea).toHaveAttribute('rows', '1')
     expect(hiddenTextarea).toHaveAttribute('rows', '1')
   })
+
+  test('rows should be the minRows when rows < minRows', () => {
+    const { getByRole } = render(<TextArea autoSize={{ minRows: 3 }} />)
+    const textarea = getByRole('textbox')
+    expect(textarea).toHaveAttribute('rows', '3')
+  })
+
+  test('rows should be the maxRows when rows > maxRows', () => {
+    const { getByRole } = render(<TextArea autoSize={{ maxRows: 1 }} />)
+    const textarea = getByRole('textbox')
+    expect(textarea).toHaveAttribute('rows', '1')
+  })
 })