Skip to content

Commit

Permalink
fix(TextArea): rows should be the smallest of default and autoSize
Browse files Browse the repository at this point in the history
  • Loading branch information
miracles1919 committed Jul 17, 2023
1 parent 5892da7 commit ee1ea82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/components/text-area/tests/text-area.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,16 @@ describe('TextArea', () => {
expect(textarea).toHaveAttribute('rows', '1')
expect(hiddenTextarea).toHaveAttribute('rows', '1')
})

test('rows should be the smallest of minRows and default', () => {
const { getByRole } = render(<TextArea autoSize={{ minRows: 1 }} />)
const textarea = getByRole('textbox')
expect(textarea).toHaveAttribute('rows', '1')
})

test('rows should be the smallest of maxRows and default', () => {
const { getByRole } = render(<TextArea autoSize={{ maxRows: 1 }} />)
const textarea = getByRole('textbox')
expect(textarea).toHaveAttribute('rows', '1')
})
})
14 changes: 12 additions & 2 deletions src/components/text-area/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,23 @@ export const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
)
}

let rows = props.rows
if (typeof autoSize === 'object') {
if (autoSize.minRows) {
rows = Math.min(autoSize.minRows, rows)
}
if (autoSize.maxRows) {
rows = Math.min(autoSize.maxRows, rows)
}
}

return withNativeProps(
props,
<div className={classPrefix}>
<textarea
ref={nativeTextAreaRef}
className={`${classPrefix}-element`}
rows={props.rows}
rows={rows}
value={value}
placeholder={props.placeholder}
onChange={e => {
Expand Down Expand Up @@ -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
/>
Expand Down

0 comments on commit ee1ea82

Please sign in to comment.