Skip to content

Commit

Permalink
refactor: adjust rows logic
Browse files Browse the repository at this point in the history
  • Loading branch information
miracles1919 committed Jul 19, 2023
1 parent ee1ea82 commit 1017b58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/components/text-area/tests/text-area.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ describe('TextArea', () => {
expect(hiddenTextarea).toHaveAttribute('rows', '1')
})

test('rows should be the smallest of minRows and default', () => {
const { getByRole } = render(<TextArea autoSize={{ minRows: 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', '1')
expect(textarea).toHaveAttribute('rows', '3')
})

test('rows should be the smallest of maxRows and default', () => {
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')
Expand Down
8 changes: 4 additions & 4 deletions src/components/text-area/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ 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 > autoSize.maxRows) {
rows = autoSize.maxRows
}
if (autoSize.maxRows) {
rows = Math.min(autoSize.maxRows, rows)
if (autoSize.minRows && rows < autoSize.minRows) {
rows = autoSize.minRows
}
}

Expand Down

0 comments on commit 1017b58

Please sign in to comment.