Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TextArea): add minHeight property, docs example #1679

Merged
merged 5 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { Form, TextArea } from 'semantic-ui-react'

const TextAreaExampleMinHeight = () => (
<Form>
<TextArea placeholder='Try adding multiple lines' autoHeight minHeight={5} />
</Form>
)

export default TextAreaExampleMinHeight
5 changes: 5 additions & 0 deletions docs/app/Examples/addons/TextArea/Usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const TextAreaTypesExamples = () => (
description='A TextArea can adjust its height to fit its contents.'
examplePath='addons/TextArea/Usage/TextAreaExampleAutoHeight'
/>
<ComponentExample
title='Min Height'
description='A TextArea can have a minimum number of rows when using autoHeight'
examplePath='addons/TextArea/Usage/TextAreaExampleMinHeight'
/>
</ExampleSection>
)

Expand Down
3 changes: 3 additions & 0 deletions src/addons/TextArea/TextArea.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface TextAreaProps {
/** Indicates whether height of the textarea fits the content or not. */
autoHeight?: boolean;

/** Indicates a minimum row height for textarea when using autoHeight. */
minHeight?: number;

/**
* Called on change.
* @param {SyntheticEvent} event - The React SyntheticEvent object
Expand Down
8 changes: 6 additions & 2 deletions src/addons/TextArea/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class TextArea extends Component {
/** Indicates whether height of the textarea fits the content or not. */
autoHeight: PropTypes.bool,

/** Indicates a minimum row height for textarea when using autoHeight. */
minHeight: PropTypes.number,

/**
* Called on change.
* @param {SyntheticEvent} event - The React SyntheticEvent object
Expand All @@ -37,6 +40,7 @@ class TextArea extends Component {

static defaultProps = {
as: 'textarea',
minHeight: 1,
}

componentDidMount() {
Expand Down Expand Up @@ -75,14 +79,14 @@ class TextArea extends Component {
updateHeight = () => {
if (!this.ref) return

const { autoHeight } = this.props
const { autoHeight, minHeight } = this.props
if (!autoHeight) return

let { borderTopWidth, borderBottomWidth } = window.getComputedStyle(this.ref)
borderTopWidth = parseInt(borderTopWidth, 10)
borderBottomWidth = parseInt(borderBottomWidth, 10)

this.ref.rows = '1'
this.ref.rows = minHeight
this.ref.style.minHeight = '0'
this.ref.style.resize = 'none'
this.ref.style.height = 'auto'
Expand Down