Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #85 from buildo/71-wrong_initial_height_when
Browse files Browse the repository at this point in the history
#71: Wrong initial height when using StyledComponents (closes #71)
  • Loading branch information
giogonzo authored Dec 12, 2017
2 parents ece767a + 68c424f commit 93a54c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 18 additions & 0 deletions examples/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
/>
```

#### Maximum height

using `maxRows`
```js
<TextareaAutosize
maxRows={3}
defaultValue={'this\nis\na\nlong\ninitial\ntext'}
/>
```

using `maxHeight`
```js
<TextareaAutosize
style={{ maxHeight: 100, boxSizing: 'border-box' }}
defaultValue={'this\nis\na\nlong\ninitial\ntext'}
/>
```

#### Prefilled

```js
Expand Down
12 changes: 7 additions & 5 deletions src/TextareaAutosize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ export default class TextareaAutosize extends React.Component<TextareaAutosize.P

if (typeof maxRows === 'number') {
this.updateLineHeight();

// this trick is needed to force "autosize" to activate the scrollbar
setTimeout(() => autosize(this.textarea));
} else {
autosize(this.textarea);
}

/*
the defer is needed to:
- force "autosize" to activate the scrollbar when this.props.maxRows is passed
- support StyledComponents (see #71)
*/
setTimeout(() => autosize(this.textarea));

if (onResize) {
this.textarea.addEventListener(RESIZED, onResize as any);
}
Expand Down

0 comments on commit 93a54c1

Please sign in to comment.